{"id":14132,"date":"2011-09-06T18:59:38","date_gmt":"2011-09-07T01:59:38","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=14132"},"modified":"2020-02-29T06:47:16","modified_gmt":"2020-02-29T13:47:16","slug":"vertical-align","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/v\/vertical-align\/","title":{"rendered":"vertical-align"},"content":{"rendered":"
The In order for this to work, the elements need to be set along a baseline. As in, The valid values are:<\/p>\n You can see examples<\/a> of each here:<\/p>\n A common use case is lining up an avatar with a username. To get them centered along a line, you’d use Each element lines up according to the line you’ve set, which doesn’t change from element to element. So, you can mix-and-match which elements have which value – the elements don’t affect each other.<\/p>\n Note that vertical-align is useful on table-cell elements as well,<\/strong> aligning the content within them. Sticking to top, middle, and bottom is the best bet though, as the other values have inconsistent cross-browser results.<\/p>\nvertical-align<\/code> property in CSS controls how elements set next to each other on a line are lined up. <\/p>\n
img {\r\n vertical-align: middle;\r\n}<\/code><\/pre>\n
inline<\/code> (e.g.
<span><\/code>,
<img><\/code>) or
inline-block<\/code> (e.g. as set by the
display<\/code><\/a> property) elements. <\/p>\n
\n
baseline<\/code> – This is the default value.<\/li>\n
top<\/code> – Align the top of the element and its descendants with the top of the entire line.<\/li>\n
bottom<\/code> – Align the bottom of the element and its descendants with the bottom of the entire line.<\/li>\n
middle<\/code> – Aligns the middle of the element with the middle of lowercase letters in the parent.<\/li>\n
text-top<\/code> – Aligns the top of the element with the top of the parent element’s font<\/li>\n
text-bottom<\/code> – Aligns the bottom of the element with the bottom of the parent element’s font.<\/li>\n
sub<\/code> – Aligns the baseline of the element with the subscript-baseline of its parent. Like where a
<sub><\/code> would sit.<\/li>\n
super<\/code> – Aligns the baseline of the element with the superscript-baseline of its parent. Like where a
<sup><\/code> would sit.<\/li>\n
length<\/code> – Aligns the baseline of the element at the given length above the baseline of its parent. (e.g. px, %, em, rem, etc.)<\/li>\n<\/ul>\n
<\/code>Check out this Pen!<\/a><\/pre>\n
vertical-align: middle;<\/code>. Although note that it centers the text according to its tallest ascender and deepest descender.<\/p>\n
More Information<\/h3>\n
\n
Browser Support<\/h3>\n
\n\n
\n Chrome<\/span><\/th>\n Safari<\/span><\/th>\n Firefox<\/span><\/th>\n Opera<\/span><\/th>\n IE<\/span><\/th>\n Android<\/span><\/th>\n iOS<\/span><\/th>\n<\/tr>\n<\/thead>\n\n \n Any<\/td>\n Any<\/td>\n Any<\/td>\n 4+<\/td>\n 4+<\/td>\n Any<\/td>\n Any<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n