CSS-three rows, three columns, and high-level Layout

Source: Internet
Author: User
Translated from: In Search of the Holy Grail
Original article: http://www.alistapart.com/articles/holygrail
This translation page is copyrighted by greengnn. For more information, see the source.

Step 1: create a structure

XHTML starts with header, footer, and container <Div id = "Header"> </div>

<Div id = "Container"> </div>

<Div id = "footer"> </div>

CSS first defines the container and leaves a position for the sideleft to be added and sideright # container {
Padding-left: 200px;/* LC width */
Padding-Right: 150px;/* RC width */
}

Our layout now looks like this

This. style. width = (this. offsetwidth & gt; 740 )? '740px ': 'auto'} "alt =" uploads/200602/13 _074820_diagram_01.gif "src =" http://www.85flash.com/Files/BeyondPic/2006-4/12/13_074820_diagram_01.gif ">

Figure 1-create a framework

Step 2: add content elements

Add content elements based on Step 1

<Div id = "Header"> </div>

<Div id = "Container">
<Div id = "center" class = "column"> </div>
<Div id = "Left" class = "column"> </div>
<Div id = "right" class = "column"> </div>
</Div>

<Div id = "footer"> </div>

Define widths and float respectively to arrange the elements on the same line, and clear the floating alignment of footer # container. Column {
Float: left;
}
# Center {
Width: 100%;
}
# Left {
Width: 200px;/* LC width */
}
# Right {
Width: 150px;/* RC width */
}
# Footer {
Clear: both;
}

The 100% width is defined for the center element to fill the available space of the montainer. The current layout is like this.

This. style. width = (this. offsetwidth & gt; 740 )? '740px ': 'auto'} "alt =" uploads/200602/13 _071_2_diagram_02.gif "src =" http://www.85flash.com/Files/BeyondPic/2006-4/12/13_074922_diagram_02.gif ">

Figure 2: add content elements

Step 3: place left in the correct position

To place left in the correct position, we will take two steps.

1. Make left and center in the same horizontal line

# Left {
Width: 200px;/* LC width */
Margin-left:-100%;
}

View results

This. style. width = (this. offsetwidth & gt; 740 )? '740px ': 'auto'} "alt =" uploads/200602/13 _075000_diagram_03.gif "src =" http://www.85flash.com/Files/BeyondPic/2006-4/12/13_075000_diagram_03.gif ">

Figure 3 -- half left

2. Use relative positioning to move left to the correct position.

# Container. Columns {
Float: left;
Position: relative;
}
# Left {
Width: 200px;/* LC width */
Margin-left:-100%;
Right: 200px;/* LC width */
}

After left is px from the center on the right, the line is displayed, and left is at its position.

This. style. width = (this. offsetwidth & gt; 740 )? '740px ': 'auto'} "alt =" uploads/200602/13 _075037_diagram_04.gif "src =" http://www.85flash.com/Files/BeyondPic/2006-4/12/13_075037_diagram_04.gif ">

Figure 4 -- left to its position

Step 4: Let the right be in the correct position.

From the perspective, we only need to push right into the padding-right of the container to see how to do it # right {
Width: 150px;/* RC width */
Margin-Right:-150px;/* RC width */
}

Now, all elements are correctly reset.

This. style. width = (this. offsetwidth & gt; 740 )? '740px ': 'auto'} "alt =" uploads/200602/13 _075115_diagram_05.gif "src =" http://www.85flash.com/Files/BeyondPic/2006-4/12/13_075115_diagram_05.gif ">

Figure 5 -- right is in the correct position

Step 5: Solve bugs and make the layout more perfect
If the browser window size changes, the center will become smaller than the left, and the perfect layout will be broken. We will set a min-width for the body.
To solve this problem, because IE does not support it, so there will be no negative impact, adjust the following body {
Min-width: 550px;/* 2x LC width + RC width */
}

At this time, in IE6 (fully open window), the left side of the left element is too far away, and then adjust * html # Left {
Left: 150px;/* RC width */
}

The size adjustment is based on the width defined above. You must adjust the size according to your actual situation.

Add padding now

The content text is appended to the container's edge. I believe it will not be very comfortable when you see it. Adjust it # Left {
Width: 180px;/* LC fullwidth-padding */
Padding: 0 10px;
Right: 200px;/* LC fullwidth */
Margin-left:-100%;
}

Of course, you can't just add left. Even if you are done, you must add a series of elements. You also need to adjust and add padding to bring new bugs. Adjust the following body {
Min-width: 630px;/* 2x (LC fullwidth +
CC padding) + RC fullwidth */
}
# Container {
Padding-left: 200px;/* LC fullwidth */
Padding-Right: pixel PX;/* RC fullwidth + CC padding */
}
# Container. Column {
Position: relative;
Float: left;
}
# Center {
Padding: 10px 20px;/* Cc padding */
Width: 100%;
}
# Left {
Width: 180px;/* LC width */
Padding: 0 10px;/* LC padding */
Right: 240px;/* LC fullwidth + CC padding */
Margin-left:-100%;
}
# Right {
Width: 130px;/* RC width */
Padding: 0 10px;/* RC padding */
Margin-Right:-pixel PX;/* RC fullwidth + CC padding */
}
# Footer {
Clear: both;
}

/*** Ie fix ***/
* Html # Left {
Left: 150px;/* RC fullwidth */
}

The padding of header and footer can be added at will, so we won't mention it here, and the length unit is more friendly with EM (EM allows users to adjust their font size using browsers)

But it cannot be used together. it is wise to select em and PX to check the effect.

Element and other issues
Using http://www.positioniseverything.net/articles/onetruelayout/equalheight
Someone translated: http://www.blueidea.com/tech/web/2006/3210.asp
The method mentioned in is not explained in detail. # Container {
Overflow: hidden;
}
# Container. Column {
Padding-bottom: 20010px;/* x + padding-bottom */
Margin-bottom:-20000px;/* x */
}
# Footer {
Position: relative;
}

Solve the bug of opera 8,CodeAdjust the following <Div id = "footer-wrapper">
<Div id = "footer"> </div>
</Div> * html body {
Overflow: hidden;
}
* Html # footer-wrapper {
Float: left;
Position: relative;
Width: 100%;
Padding-bottom: 10010px;
Margin-bottom:-pixel PX;
Background: # FFF;/* same as body
Background */
}

the entire process is over. Check the final result and use the W3C standard type.

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.