CSS Typical layout

Source: Internet
Author: User

Directory:

One, horizontal layout

Two, vertical layout

Three, two-column layout

Four-, three-column layout

Five, multi-column layout

Six, equal height layout

One, horizontal layout

1,text-align

      . Parent{        text-align: center;      }       .Child {        display: inline-block;      }

2,margin

      .Child {        width: 200px;         Margin: 0 auto;      }

3,position

      . Parent{        position: relative;      }       .Child {        position: absolute;         left: 50%;         width: 200px;         margin-left: -100px;      }

4,table

    .Child {        display: table;         Margin: 0 auto;      }

5,flex

1) justify-content

    . Parent{        display: flex;         Justify-content: center;      }

2) margin

      . Parent{        display: flex;      }       .Child {        margin: 0 auto;      }

Two, vertical layout

1,position

    . Parent{        position: relative;      }       .Child {        position: absolute;         Top: 50%;         height: 200px;         margin-top: -100px;      }

2,flex

1), Align-items

    . Parent{        display: flex;         Align-items: center;      }

2), margin

      . Parent{        display: flex;      }       .Child {        margin: auto 0;      }

Three, two-column layout

1, left fixed width, right adaptive

      . Parent::after{        content: ';         Clear: both;         display: table;      }       .Left {      float: left;       Width: 200px;      }       . Main{        margin-left: 200px;      }

  {        display: table;         table-layout: fixed;         width: 100%;    } {width: 100px;        }             . Left,    {        display: table-cell;    }

2, left adaptive, right adaptive

    . Parent::after{        content: ';         Clear: both;         display: table;      }       .Left {      float: left;      }       . Main{        overflow:hidden;      }

Four-, three-column layout

Fixed width on both sides, intermediate adaptive

1,float+margin

<style>. Parent::after{content:"';Clear:both;Display:Table; }. Left{float: Left;width:200px; }. Center{margin:0 200px; }. Right{float: Right;width:200px; }</style>

2,position+margin

<style>. Left{position:Absolute;Top:0; Left:0;width:200px; }. Right{position:Absolute;Top:0; Right:0;width:200px; }. Center{margin:0 210px; }</style><body> <div class= "left" > Right </div> <div class= "center" > in </div> < Div class= "Right" > R </div></body>

Five, multi-column layout

1, Negative margin

        {            margin-left: -20px        }/        * assume that the spacing between columns is 20px*                 / {            float: left;             Width: 25%;             padding-left: 20px;             box-sizing: border-box;        }

2,flex

      {            display: flex;        } {flex: 1;            }                 {margin-left: 20px;            }                 

CSS Typical 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.