Div+css Common page Layout tips!

Source: Internet
Author: User

The following is my div+css commonly used page layout skills, only for learning and reference!

First layout: left fixed width, right adaptive width

HTML Markup


<div id= "left" >left sidebar</div>
<div id= "Content" >main content</div>

CSS Code


<style type= "Text/css" >

*{
margin:0;
padding:0;
}

#left {
Float:left;
width:220px;
Background-color:green;
}

#content {
Background-color:orange;
margin-left:220px; /*== equals left column width ==*/
}
</style>

Second layout: left adaptive width, right fixed width

HTML Markup

<div id= "wrapper" class= "Clearfix" >
<div id= "Content-wrapper" >
<div id= "Content" >
Content on the left
</div>
</div>
<div id= "NAV" >
Content on the right
</div>
</div>

CSS Code

Body {
padding:0;
margin:0;
}

#wrapper {
width:960px;
border:1px solid #333;
margin:0 Auto;
}

#nav {
width:200px;
Float:right;
}

#content-wrapper {
Margin-right: -200px;
Float:left;
width:100%;
}

#content {
margin-right:200px;
Padding:0 10px;
}

. clearfix:after {
height:0;
Content: ".";
Display:block;
Clear:both;
Visibility:hidden;
}

Third layout: three-column layout, fixed left and right, middle adaptive width

HTML Markup

Div class= "Left" > I am left</div>
<div class= "Right" > I'm right</div>.
<div class= "center" > I am center</div>

CSS Code

body,div{margin:0; padding:0;}
div{height:200px; color: #F00;}
. left{float:left; width:100px; background: #00f; _margin-right:-3px;}
. right{float:right; width:100px; background: #0f0; _margin-left:-3px;}
. center{background: #333; margin:0 100px; _margin:0 97PX;}

3px Gap bug in IE6

In IE6, we see a 3px interval between columns, which is only a problem with IE6. If the Margin-left and margin-right in the middle column are all 0, just set the Margin-right on the left column to -3px and the Margin-left on the right column to -3px. However, if the Margin-left and margin-right of the middle column are respectively the width of the left and right columns, even if the margin-right of the column is set to -3PX, the margin-left of the column in the row is not effective. It's time to set the Margin-left in the middle column to the left column width -3px,margin-right to the right column width -3px.

The fourth layout: equal height layout, that is, in the implementation of the above three layouts, but also to achieve the same level of the left and right area (the content is unlimited, whichever is the maximum height)

<style>
body{padding:0; margin:0; color: #f00;}
. container{margin:0 Auto; width:600px; border:3px solid #00C;
Overflow:hidden; /* This beyond the hidden statement is not written in the IE6 is also possible * *
}
. left{float:left; width:150px; background: #B0B0B0;
padding-bottom:2000px;
margin-bottom:-2000px;
}
. right{float:left; width:450px; background: #6CC;
padding-bottom:2000px;
margin-bottom:-2000px;
}
</style>
<body>
<div class= "Container" >
<div class= "Left" > I am left</div>
<div class= "Right" > I am right<br><br><br> now I am taller than left, but left with its padding-bottom compensated for this part of the height </ Div>
<div style= "Clear:both" ></div>
</div>
</body>
The principle of implementation: first set the Padding-bottom of the column to a value that is large enough, and then set the Margin-bottom of the column to offset the positive values of the previous padding-bottom, the parent container settings are beyond the hidden, The height of the parent container is still the height of the column in the Padding-bottom when it is not set, and when any column in it has a height increase, the height of the parent container is propped up to the height of the highest column in it. Other columns that are shorter than this list use their padding-bottom to compensate for this part of the height difference. Because the background is can be used in padding occupied space, and the border is also following the padding change, so the successful completion of a fake. Source Text address: http://www.zuowenjun.cn/post/2014/08/21/17.html
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.