Then we can use the line-height property for both div and span. We can use the br tag to break the line and make it a multiple-line text. We can place a span tag inside a div tag and put multiple lines inside the span tag. We can also align multiple numbers of lines vertically using the line-height property. Use span Inside a div Along With the line-height Property to Align Text Vertically in CSS The example below shows that the text is aligned vertically to the center of the div containing height of 100 px and border of 1px solid black using CSS line-height property. Lastly, give the div a border of 1px solid black to see the vertical alignment. Give the div a height of 100px and line-height of 100px to vertically align the text to the center of the div. Write a one-line text Vertically aligned inside the div. Let us give the div a class name of center. We can give line-height any value according to our requirement on where we want to align the text vertically.įor example, create a div and write a one-line text inside it. This technique will not work if the text has line breaks or is of more than one line. However, we can also use it to align our one-line text vertically. It is used to set the distance between lines of text. The line-height CSS property sets the height of a line box. If we have single-line text, we can use the line-height property to align the text vertically within a div.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |