CSS left and right columns fixed right adaptive

Source: Internet
Author: User

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.


left

right

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.


left

right

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.