Horizontal Alignment of two elements

Source: Internet
Author: User

 

There are three solutions:

1. Use float

<Div> 123 </div> <div> 456 </div>

The effect is as follows:

123

456

 

Float can be used for horizontal alignment of the two elements, but the height of the element outside is zero at this time.

 

. Clearfix: After {visibility: hidden; display: block; font-size: 0; content: ""; clear: Both; Height: 0 ;}. clearfix {display: inline-table;}/* hides from IE-Mac \ */* HTML. clearfix {Height: 1% ;}. clearfix {display: block;}/* end hide from IE-Mac */

You only need to add the. Clearfix class to the parent Div.

2. Use "display: inline-block" for the elements in the inline block-level elements to set their height and width. However, it may still seem wrong. You only need to add vertical-align: Top; To horizontally align.

 

3. The parent element uses relative positioning, and the child element uses absolute positioning.

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.