Two layout

1, two width adaptive layout
  two floating arrangement may be accomplished, set left floating in the left column, right column floating right set, then set so that the outer margin of the province.

  When using a floating element, the element will affect around, then you need to clear the float, usually using two methods. May be provided to the element affected clear: both, i.e. remove both floating elements, which may be provided on one side of the floating concrete clear: clear: left or clear: right, but must clearly know in the end side which needs to be cleared effects of floating. May be provided to the floating parent container width, or 100%, and set overflow: hidden, the hidden overflow can achieve the effect of floating clear.

  Similarly, two width adaptive and need to be set as a percentage of the width, so that when the browser window is adjusted according to the size of the window contents, as a percentage to automatically adjust the size of the content.image description

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>宽度自适应两列布局</title>
<style>
*{margin:0;padding:0;}
#herder{
    height:50px;
    background:blue;
}
.main-left{
    width:30%;
    height:800px;
    background:red;
    float:left;
}
.main-right{
    width:70%;
    height:800px;
    background:pink;
    float:right;
}
#footer{
    clear:both;
    height:50px;
    background:gray;
}
</style>
</head>
<body>
<div id="herder">页头</div>
<div class="main-left">左列</div>
<div class="main-right">右列</div>
<div id="footer">页脚</div>
</body>
</html>

2, two fixed-width layout
  width of two adaptive layout site are less commonly used, the two most commonly used fixed-width layout.

  To achieve the two fixed-width layout, it is also very simple, just need about two wrapped up, that is to send them a parent container, then a fixed width of the parent container, the width of the parent container is fixed, then the two columns on specific pixel width may be provided, and thus achieving the two fixed-width layout.

image description

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>固定宽度两列布局</title>
<style>
*{margin:0;padding:0;}
#herder{
    height:50px;
    background:blue;
}
#main{
    width:960px;
    margin:0 auto;
    overflow:hidden;
}
#main .main-left{
    width:288px;
    height:800px;
    background:red;
    float:left;
}
#main .main-right{
    width:672px;
    height:800px;
    background:pink;
    float:right;
}
#footer{
    width:960px;
    height:50px;
    background:gray;
    margin:0 auto;
}
</style>
</head>
<body>
<div id="herder">页头</div>
<div id="main">
    <div class="main-left">左列</div>
    <div class="main-right">右列</div>
</div>
<div id="footer">页脚</div>
</body>
</html>

3, two centering adaptive layout
  Similarly, just to give the width of a given parent container, and then let the parent container centered horizontally.
image description

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>两列居中自适应布局</title>
<style>
*{margin:0;padding:0;}
#herder{
    height:50px;
    background:blue;
}
#main{
    width:80%;
    margin:0 auto;
    overflow:hidden;
}
#main .main-left{
    width:20%;
    height:800px;
    background:red;
    float:left;
}
#main .main-right{
    width:80%;
    height:800px;
    background:pink;
    float:right;
}
#footer{
    width:80%;
    height:50px;
    background:gray;
    margin:0 auto;
}
</style>
</head>
<body>
<div id="herder">页头</div>
<div id="main">
    <div class="main-left">左列</div>
    <div class="main-right">右列</div>
</div>
<div id="footer">页脚</div>
</body>
</html>

4, the fixed width of the transverse two-column layout
  same and single layout, all blocks can be contained in a container, we arranged to do so easily, but increases the code meaningless, the fixed width is the width of a given parent container, and then use intermediate body float.
image description

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>横向两列布局</title>
<style>
*{margin:0;padding:0;}
#warp{
    width:960px;
    margin:0 auto;
    margin-top:10px;
}
#herder{
    height:50px;
    background:blue;
}
#nav{
    height:30px;
    background:orange;
    margin:10px 0;
}
#main{
    width:100%;
    margin-bottom:10px;
    overflow:hidden;
}
#main .main-left{
    width:640px;
    height:200px;
    background:yellow;
    float:left;
}
#main .main-right{
    width:300px;
    height:200px;
    background:pink;
    float:right;
}
#content{
    width:100%;
    overflow:hidden;
}
#content .content-left{
    width:640px;
    height:800px;
    background:lightgreen;
    float:left;
}
#content .content-right-sup{
    width:300px;
    height:500px;
    background:lightblue;
    float:right;
}
#content .content-right-sub{
    width:300px;
    height:240px;
    background:purple;
    margin-top:20px;
    float:right;
}
#footer{
    height:50px;
    background:gray;
    margin-top:10px;
}
</style>
</head>
<body>
<div id="warp">
    <div id="herder">页头</div>
    <div id="nav">导航</div>
    <div id="main">
        <div class="main-left">左-上</div>
        <div class="main-right">右-上</div>
    </div>
    <div id="content">
        <div class="content-left">左-下</div>
        <div class="content-right-sup">右-上</div>
        <div class="content-right-sub">右-下</div>
    </div>
    <div id="footer">页脚</div>
</div>
</body>
</html>

Guess you like

Origin www.cnblogs.com/jlfw/p/12521348.html