Let two DIVs display side by side_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:51:17
Original
1698 people have browsed it

一、使用display的inline属性

Html代码  

  1. AAAA
      
  2. BBBB
      

 

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>
Copy after login

二、通过设置float来让Div并排显示

Html代码

  1. 1111
  2. 2222
    2222
    2222

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     <!-- 如果不用clear?性可能?出???器不兼容??,clear??元素周??有浮?元素 -->  8     <div   style="clear:both"></div>  9  </div>
Copy after login

 

 

 

 

三、对于两个div并排,左边为绝对宽度,右边为相对宽度的,需要用到这种布局的情况比较多见,如左边为导航,右边为内容的页面

    1、将最大的容器padding-left固定宽度,左边的固定宽度的一块position:absolute,然后right的一块width为百分百

    2、 使用position:absolute。代码如下。

Html代码  

  1.   
  2. left
      
  3.   

  这段代码主要涉及到以下两点点比较重要的:

 (1)兼容firefox实现div高度100%;
 (2)div绝对定位的妙用;在页面布局的时候,position:absolute如果灵活的应用,可以达到很好的效果。

  3、 使用float解决div左右布局,左为绝对宽度,右为相对宽度问题

Html代码  

  1.   
  2.   
  3.   

4. The code is as follows. Method 3 may not meet the requirements of the question, but it can achieve the same page effect. Mainly using the float attribute of div.

Html code

    1. div id="left">left
    2. Right
🎜>
Related labels:
source:php.cn
Previous article:How to make the web page display the icon you made in the browser title bar ico_html/css_WEB-ITnose Next article:Browser compatibility for web front-end development (continuous updates)_html/css_WEB-ITnose
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template