Let two div display side-by

Source: Internet
Author: User

One, using the inline property of display

HTML code
    1. <div style="width:300px; Height:auto; Float:left; Display:inline ">aaaa</div>
    2. <div style="width:300px; Height:auto; Float:left; Display:inline ">bbbb</div>

Second, by setting float to let div display

HTML code
  1. <style>
  2. #left, #right {float:left;border:1px solid red; padding:10px;}
  3. </style>
  4. <div id= "main">
  5. <div id= "left"> 1111 </div>
  6. <div id= "right"> 2222 <br> 2222 <br> 2222 </ div>
  7. <!--If you do not have a clear component, you may have a browser incompatibility problem, and clear this element has no floating element around--
  8. <div style="Clear:both"></div>
  9. </div>

Three, for two Div side-by, the left is the absolute width, the right is relative width, need to use this layout of the situation more see, such as the left for navigation, the right side of the content of the page

1, the largest container padding-left fixed width, the left fixed width of a piece of position:absolute, and then right a piece of width for hundred percent

2, use Position:absolute. The code is as follows.

HTML code
  1. <style>
  2. body{margin:0; height:100%}
  3. html{height:100%}/* compatible with Firefox div height 100%*/
  4. #left {position:absolute; top:0; left:0; width:200px; height:100%;
  5. #right {margin-left:200px; height:100%;
  6. </style>
  7. <div id="left">left</div>
  8. <div id="right">right</div>

This code mainly involves the following two points are more important:

(1) compatible with Firefox to achieve div height 100%;
(2) The magic of absolute positioning of div; When the page layout, Position:absolute if the flexible application, can achieve good results.


3. Use float to solve the div layout, left is absolute width, right is relative width problem

HTML code
  1. <style type="Text/css">
  2. body{margin:0; height:100%}
  3. html{height:100%}
  4. #left {width:150px; height:100%; float:left; _margin-right:-3px; yellow}
  5. #main {height:100%; green}
  6. </style>
  7. <div id="left"></div>
  8. <div id="main"></div>

4, the code is as follows. Method 3 may not follow the title, but can achieve the same page effect. The main use of the DIV's float property.

HTML code
    1. <style>
    2. body{margin:0; height:100%}
    3. html{height:100%}/* compatible with Firefox div height 100%*/
    4. #left {width:200px; height:100%; Float:left}
    5. #main {width:100%; height:100%;
    6. </style>
    7. <div id="main">
    8. <div id="left">left</div>
    9. Right
    10. </div>

Let two div display side-by

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.