Two-column layout (one-column fixed width, one-column adaptive, high column height), two-column adaptive

Source: Internet
Author: User

Two-column layout (one-column fixed width, one-column adaptive, high column height), two-column adaptive

Structure:

1    <div class="parent">2         <div class="left">3             <p>left</p>4         </div>5         <div class="right">6             <p>right</p>7             <p>right</p>8         </div>9     </div>

1. Use table + table-cell to implement the layout of two columns (one column is fixed width, one column is adaptive, and the table is automatically equal to the automatic height of two columns)

1. parent {2 background-color: gray; 3 width: 500px; 4 height: 300px; 5 padding: 10px; 6 box-sizing: border-box; 7 8 display: table; 9 table-layout: fixed; 10 table-layout: fixed;/* accelerate table rendering to give priority to layout */11} 12. left {13 display: table-cell; 14 width: 100px; 15 16 background-color: skyblue; 17 border-right: 10px solid transparent; 18 background-clip: padding-box; /* set the display position of the background */19} 20. right {21 display: table-cell; 22 background-color: greenyellow; 23}

2. Use flex for two column la S (one column is fixed width, one column is adaptive, and the column height is high). The default align-item attribute of flex is stretch.

1. parent {2 background-color: gray; 3 width: 500px; 4 height: 300px; 5 padding: 10px; 6 7 display: flex; 8} 9. left {10 width: 100px; 11 margin-right: 10px; 12 background-color: skyblue; 13} 14. right {15 flex: 1;/* fill in the remaining part */16 background-color: greenyellow; 17}

3. Use float (pseudo height)

1. parent {2 background-color: gray; 3 width: 500px; 4 height: 300px; 5 padding: 10px; 6 7 overflow: hidden;/* truncation */8} 9. left ,. right {10 padding-bottom: 99999px; 11 margin-bottom:-99999px; 12}/* Climb */13. left {14 width: 100px; 15 background-color: skyblue; 16 margin-right: 10px; 17 float: left; 18 19} 20. right {21 overflow: hidden; 22 background-color: yellowgreen; 23}

 

Related Article

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.