CSS3 set Box-pack and box-align to align the elements inside the div vertically

Source: Internet
Author: User

As long as you set the element's Box-pack and box-align, these two properties are currently only WebKit and Moz support, to set the vertical center, you only need to set the values of these two properties to center, the need for friends can refer to the following The previous way to handle vertical centering is to set the div's height and line-height to be the same value, and now it's not that troublesome. These two properties are currently only supported by WebKit and Moz, as long as the box-pack and box-align of the elements are set. Where Box-pack control is the horizontal left and right, the values are: Start (left), Center (center), End (right). The box-align values are: Start (top), center (center), End (bottom). If we want to set the vertical center, we just need to set the values of both properties to center. Of course, the premise is to use the CSS3 box layout, which will set the display of the outer element to box

Copy CodeThe code is as follows:
<style type= "Text/css" >
#container {
Display:box;
Display:-webkit-box;
Display:-moz-box;
width:800px;
height:200px;
border:1px solid #ccc;
-webkit-box-pack:center;
-moz-box-pack:center;
-webkit-box-align:center;
-moz-box-align:center;
}
#div1 {
Background:orange;
}
#div2 {
Background:yellow;
}
#div3 {
Background:green;
}
</style>
<body>
<div id= "Container" >
<div id= "DIV1" > Column 1</div>
<div id= "DIV2" > Column 2</div>
<div id= "Div3" > Column 3</div>
</div>
</body>

CSS3 set Box-pack and box-align to align the elements inside the div vertically

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.