A CSS method for Heng Lie typesetting layout

Source: Internet
Author: User
first, the method of using float to realize Heng Lie layout

As shown below: Both P1 and P2 can choose to float 50% to the left or right to display on the same line

P1 P2

Analysis:

1, the first line of the first picture and the last picture of the left and right margin is 10px, the middle picture of the left and right margin is 5px. The layout is as follows:


<section class= "Active_p1" >        <p>                    </p>        <p >                    </p>        <p>                    </p>    </section>


. ACTIVE_P1 p {    float:left;    width:33.33%;    Box-sizing:border-box;} . Active_p1 P:nth-child (1) {    padding-left:10px;}. Active_p1 P:nth-child (3) {    padding-right:10px;}. active_ P1 P:nth-child (2) {    padding:0 5px;}

2, the second line only the middle picture the most margin is 5px; the layout is as follows:


<section class= "ACTIVE_P2" >        <p>                    </p>        <p>                    </p>        <p>                    </p>    </section>


. ACTIVE_P2 p {    width:33.33%;    Float:left;    Box-sizing:border-box;} . ACTIVE_P2 P:nth-child (2) {    padding:0px 5px;}

Note: If there are no other styles after using Box-sizing:border-box, all blocks will be pasted together, without any spacing between them.

Second, the use of Display:inline-block

Display:inline-block most transformations for a row block, this property is not recommended for column layout. Because Inline-block can not replace float completely.

The layout in the red box is the most classic layout using Display:inline-block.



. Consume_h  span {    display:inline-block;}. Consume_h  span:before {    content: "\f120";    Display:inline-block;    margin-right:5px;    margin-left:10px;    font-family: "Ionicons";    Speak:none;    Font-style:normal;    Font-weight:normal;    Font-variant:normal;    Text-transform:none;    Text-rendering:auto;    line-height:1;    -webkit-font-smoothing:antialiased;}

Pseudo-classes are used here, and the definition and use of pseudo-classes are not introduced here.

There is also a classic layout:

This layout is generally:


<p>                        <p> Test do not    shoot            </p> </p>

The use of positioning Position:absolute is often used for left fixed, right-adaptive conditions.

    1. Relative positioning of P

    2. Absolute positioning of img

    3. P for relative positioning

Third, using flexible box to achieve a true sense of fluid layout

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.