What this article brings to you is an introduction to three methods (code) of implementing two-column layout using CSS. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Floating layout
The left column has a fixed width and floats to the left. The main content on the right uses margin-left to leave the width of the left column. The default width For auto, the remaining width is automatically filled.
<div class="one"></div> <div class="two"></div>
.one{ float: left; width: 200px; height: 200px; background: darkcyan } .two{ margin-left: 200px; height: 200px; background: salmon }
The right side has a fixed width, and the left side is adaptive in the same way. Just float the fixed column to the right and use margin-right to free up its width.
<div class="one"></div> <div class="two"></div>
.one{ float: right; width: 200px; height: 200px; background: darkcyan } .two{ margin-right: 200px; height: 200px; background: salmon }
2. Floating layout with negative margins (two-column version of double-wing layout)
<div class="aside"></div> <div class="main"> <div class="content"></div> </div>
.aside{ width: 300px; height: 100px; background:darkcyan; margin-right: -100%; float: left; } .main{ width: 100%; float: left; } .content{ margin-left: 300px; background: salmon; }
3. Absolute positioning
<div class="left"></div> <div class="right"></div>
.left{ width: 200px; height: 200px; position: absolute; background: darkcyan } .right{ height: 200px; margin-left:200px; background: salmon; }
Related recommendations:
Css layout series-upper and lower column layout_html/css_WEB-ITnose
CSS: three-column layout, fixed on both sides, adaptive in the middle_html/css_WEB-ITnose
css Multi-column adaptive Layout_html/css_WEB-ITnose
The above is the detailed content of Introduction to three methods to implement two-column layout with css (code). For more information, please follow other related articles on the PHP Chinese website!