×

Html & Html5

The World's best Software Development Study Portal

CSS Vertical Align


If we want to align any element vertically than through this property of CSS we can align it vertically. But as we have discussed previously in display property. So here also this property we can use in Block and inline-block elements not in inline elements.

Let's understand this by the following program:-


<!DOCTYPE html>

<html>

<head>

<style>

img.texttop {

      vertical-align: text-top;

}

img.textbottom {

      vertical-align: text-bottom;

}

</style>

</head>

<body>

<p> <img src="pythonimage/redfort.jpg" class="texttop" alt="Good Morning Friends"> Text-top alignment. </p>

<p> <img src="pythonimage/redfort.jpg" class="textbottom" alt="Good Morning Friends>Text-bottom alignment</p>

</body>

</html>



Output of the Program









Good Morning Friends Text-top alignment.



Good Morning FriendsText-bottom alignment







So this is how we can align the items.


Some more values of vertical alignment property.These are mentioned below with description


Value Description
length It is used to increase or decrease length of the element by the specified length. negative values are also allowed.
% It is used to increase or decrease the element in a percent of the "line-height" property. negative values are allowed.
baseline It aligns the baseline of element with the baseline of parent element. This is a default value.
sub It aligns the element as if it was subscript.
super It aligns the element as if it was superscript.
top It aligns the top of the element with the top of the tallest element on the line.
bottom It aligns the bottom of the element with the lowest element on the line.
text-top the top of the element is aligned with the top of the parent element's font.
middle the element is placed in the middle of the parent element.
text-bottom the bottom of the element is aligned with the bottom of the parent element's font.
initial It sets this property to Its default value.
inherit inherits this property from Its parent element.





CSS 3 training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute