CSS Vertical Centering

Source: Internet
Author: User

1. line-height: single-line text vertically centered
Applies to the button drop-down box when the line height of a single line of text is set, the text is positioned vertically in the middle of the row height.

2.line-height + inline-block Vertical centering of multiple elements or multiple lines of multiple objects
Treating multiple elements or multiline elements as a row element requires that the data be wrapped in a layer, set to Inline-block, and use Inline-block instead of the height setting in the outer layer of the Inline-block object.
  

<style>
. box{width:500px; border:1px solid #f00; Margin:auto; line-height:200px; Text-align:center;}. box. content{Display:inline-block; Height:auto; Line-height:1; width:400px; Background: #ccc;} </style>
<Divclass= "box"> <Divclass= "Content">aaaaaaaaaa<ahref="">bbbbbbbbbbbbbb</a>CCCCCCCCCCCCCCCCCC</Div></Div>

3.:befor + inline-block Multi-Object CSS vertical centering
: Before pseudo-class element +inline-block attribute the advantage is that the sub-element center can not need to set a special height, will: before Pseudo-class element set to 100% high Inline-block, Collocation will be required in the play sub-elements are also set to Inline-block properties, you can use the Vertical-align:minddle to achieve vertical center


  

  


  

CSS Vertical Centering

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.