Home  >  Article  >  Web Front-end  >  Introduction to three methods to implement two-column layout with css (code)

Introduction to three methods to implement two-column layout with css (code)

不言
不言Original
2018-08-21 10:17:163717browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn