The problem of the vertical center of the page text in the DIV+CSS layout

Source: Internet
Author: User
css| Page | questions

1. Single text

Set the height of the div is the same as the line height of the text can be, that is, line-height and the height of the value is the same, and finally give Div a over-flow:hidden, so that the excess part of the hidden.

This method supports block-level and inline-pole elements as well as all browsers, but only one row, and IE does not support the center of < img >, the reason to use Overflow:hidden is because when the user enlarges the font, the word will go beyond the scope of the Div.

div{
height:20px;
line-height:20px;
Overflow:hidden;
}

2. Multiple lines of text

It's simple, just set the same padding-bottom and Padding-top.

div{
padding-top:20px;
padding-bottom:20px;
}

This method supports both block-level and inline-pole elements as well as non-text content, including pictures, and so on, and all browsers are not enough to fix the height

Now more useful on the two methods, of course, you can also use the browser CSS hack, using less, not much to say.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.