The two divs are side by side, the left side is absolute width, and the right side is relative width. I often encounter this problem. My general solution is to fix the maximum container padding-left width, position: absolute, and the width of right is
I learned three solutions for people today.
The two divs are side by side, which is easy to implement. How can we set the Left Div to a fixed width and the right div to a relative width? This layout is usually used, for example, navigation on the left and content on the right. I have come up with two implementation methods for the moment.
Method 1 , Use position: absolute. Code As follows.
<Style>
Body {margin: 0; Height: 100%}
HTML {Height: 100%}/* Div height 100% compatible with Firefox */
# Left {Position: absolute ; Top: 0; left: 0; width: 200px; Height: 100%; Background-color: # cccccc}
# Right { Margin-left: 200px ; Height: 100%; Background-color: # 0099ff}
</Style>
<Div id = "Left"> left </div>
<Div id = "right"> right </div>
This code mainly involves the following two important points:
(1) compatible with Firefox to achieve a div height of 100%;
(2) div is an excellent choice for absolute positioning. In the page layout, position: absolute can achieve good results if it is applied flexibly.
Method 2 Use float to solve the problem of Div layout left and right, with absolute width left and relative width right
<Style type = "text/CSS">
Body {margin: 0; Height: 100%}
HTML {Height: 100%}
# Left {width: 150px; Height: 100%; float: Left; _ margin-Right:-3px; Background-color: yellow}
# Main {Height: 100%; Background-color: Green}
</Style>
<Div id = "Left"> </div>
<Div id = "Main"> </div>
method 3 . The Code is as follows. Method 2 may not follow the requirements of the question, but it can achieve the same page effect. It mainly uses the float attribute of Div.
The two divs are side by side, the left side is absolute width, and the right side is relative width. I often encounter this problem. My general solution is to fix the maximum container padding-left width, position: absolute, and the width of right is
I learned three solutions for people today.
The two divs are side by side, which is easy to implement. How can we set the Left Div to a fixed width and the right div to a relative width? This layout is usually used, for example, navigation on the left and content on the right. I have come up with two implementation methods for the moment.
Method 1 , Use position: absolute. The Code is as follows.
<Style>
Body {margin: 0; Height: 100%}
HTML {Height: 100%}/* Div height 100% compatible with Firefox */
# Left { Position: absolute ; Top: 0; left: 0; width: 200px; Height: 100%; Background-color: # cccccc}
# Right { Margin-left: 200px ; Height: 100%; Background-color: # 0099ff}
</Style>
<Div id = "Left"> left </div>
<Div id = "right"> right </div>
This code mainly involves the following two important points:
(1) compatible with Firefox to achieve a div height of 100%;
(2) Div absolute positioning is an amazing use; position: absolute can achieve good results if it is applied flexibly during page layout.
Method 2 Use float to solve the problem of Div layout left and right, with absolute width left and relative width right
<Style type = "text/CSS">
Body {margin: 0; Height: 100%}
HTML {Height: 100%}
# Left {width: 150px; Height: 100%; float: Left; _ margin-Right:-3px; Background-color: yellow}
# Main {Height: 100%; Background-color: Green}
</Style>
<Div id = "Left"> </div>
<Div id = "Main"> </div>
method 3 . The Code is as follows. Method 2 may not follow the requirements of the question, but it can achieve the same page effect. It mainly uses the float attribute of Div.