Example
The code is as follows: |
Copy code |
<! Doctype html> <Html lang = "zh-CN"> <Head> <Meta charset = "UTF-8"> <Title> fixed width in the left column and absolute positioning method in adaptive mode in the right column </title> <Style type = "text/css"> Body { Margin: 0; } # Nav { Top: 0; Left: 0; Width: 230px; Height: 600px; Background: # ccc; Position: absolute; } # Main { Height: 600px; Margin-left: 230px; Background: # 0099ff; } </Style> </Head> <Body> <Div id = "container"> <Div id = "nav"> Left Column </Div> <Div id = "main"> Right column </Div> </Div> </Body> </Html> |
It looks nice, ..
Because the left column uses absolute positioning and is out of the document stream, there is a defect that the container cannot be opened when the height of the left column is greater than that of the right column, this defect does not affect the layout of the two columns, but if there is a bottom column under the two columns, the bottom column and the left column will overlap:
The code is as follows: |
Copy code |
<! Doctype html> <Html lang = "zh-CN"> <Head> <Meta charset = "UTF-8"> <Title> fixed width in the left column and absolute positioning method in adaptive mode in the right column </title> <Style type = "text/css"> Body { Margin: 0; } # Nav { Top: 0; Left: 0; Width: 230px; Height: 600px; Background: # ccc; Position: absolute; } # Main { Height: 400px; Margin-left: 230px; Background: # 0099ff; } # Footer { Text-align: center; Background: #009000; } </Style> </Head> <Body> <Div id = "container"> <Div id = "nav"> Left Column </Div> <Div id = "main"> Right column </Div> </Div> <Div id = "footer"> Bottom Bar </Div> </Body> </Html> |
Let's take a look at the second method: fixed width on the left bar and adaptive negative margin method on the right bar:
The code is as follows: |
Copy code |
<! Doctype html> <Html lang = "zh-CN"> <Head> <Meta charset = "UTF-8"> <Title> fixed width in the left column and adaptive negative margin method in the right column </title> <Style type = "text/css"> Body { Margin: 0; } # Container { Margin-left: 230px; _ Zoom: 1; /* The left column of IE6 compatibility disappears */ } # Nav { Float: left; Width: 230px; Height: 600px; Background: # ccc; Margin-left:-230px; Position: relative; /* The left column of IE6 compatibility disappears. IE6 is really hard to worry about. >_< */ } # Main { Height: 600px; Background: # 0099ff; } </Style> </Head> <Body> <Div id = "container"> <Div id = "nav"> Left Column </Div> <Div id = "main"> Right column </Div> </Div> </Body> </Html> |
In this way, no matter how the height of the two columns changes, there will be no problem:
The code is as follows: |
Copy code |
<! Doctype html> <Html lang = "zh-CN"> <Head> <Meta charset = "UTF-8"> <Title> fixed width in the left column and adaptive negative margin method in the right column </title> <Style type = "text/css"> Body { Margin: 0; } # Container { Margin-left: 230px; _ Zoom: 1; /* The left column of IE6 compatibility disappears */ } # Nav { Float: left; Width: 230px; Height: 600px; Background: # ccc; Margin-left:-230px; Position: relative; /* The left column of IE6 compatibility disappears. IE6 is really hard to worry about. >_< */ } # Main { Height: 400px; Background: # 0099ff; } # Footer { Clear: both; Text-align: center; Background: #009000; } </Style> </Head> <Body> <Div id = "container"> <Div id = "nav"> Left Column </Div> <Div id = "main"> Right column </Div> </Div> <Div id = "footer"> Bottom Bar </Div> </Body> </Html> |