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

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

不言
Release: 2018-08-21 10:17:16
Original
3754 people have browsed it

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>
Copy after login
        .one{
            float: left;
            width: 200px;
            height: 200px;
            background: darkcyan
        }
        .two{
            margin-left: 200px;
            height: 200px;
            background: salmon
        }
Copy after login

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>
Copy after login
        .one{
            float: right;
            width: 200px;
            height: 200px;
            background: darkcyan
        }
        .two{
            margin-right: 200px;
            height: 200px;
            background: salmon
        }
Copy after login

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>
Copy after login
        .aside{
            width: 300px;
            height: 100px;
            background:darkcyan;
            margin-right: -100%;
            float: left;
        }
        .main{
            width: 100%;
            float: left;
        }
        .content{
            margin-left: 300px;
            background: salmon;
        }
Copy after login

3. Absolute positioning

    <div class="left"></div>
    <div class="right"></div>
Copy after login
        .left{
            width: 200px;
            height: 200px;
            position: absolute;
            background: darkcyan
        }
        .right{
            height: 200px;
            margin-left:200px; 
            background: salmon;
        }
Copy after login

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!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template