(转)DIV入门之流式布局:float,clear <等>

来源:互联网 发布:股票买卖模拟软件 编辑:程序博客网 时间:2024/05/22 10:16

http://blog.csdn.net/kissme_a/article/details/18910991


float有三种:(注意每行的长度,如div总长度超过行长,则会下调,发生错误)!!!

float:left表示允许向左流动

float:right表示允许向右流动

float:none表示不允许流动

[css] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. //style.css  
  2. #first{  
  3.     width:300px;  
  4.     height:200px;  
  5.     background:red;  
  6.     float:left  
  7. }  
  8.   
  9. #second{  
  10.     width:300px;  
  11.     height:200px;  
  12.     background:pink;  
  13.     float:right  
  14. }  
  15.   
  16. #third{  
  17.     width:300px;  
  18.     height:200px;  
  19.     background:green;  
  20.     float:right  
  21. }  
  22.   
  23.   
  24. #four{  
  25.     width:300px;  
  26.     height:200px;  
  27.     background:#fab;  
  28.     float:left  
  29. }  

[css] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <html>  
  2. <head>  
  3.     <title>div的概念</title>  
  4.     <link rel = "stylesheet" href = "style.css" type = "css/style.css"/>  
  5. </head>  
  6. <body>  
  7.     <div id="first">第一个div</div>  
  8.     <div id="second">第二个div</div>  
  9.     <div id="third">第三个div</div>  
  10.     <div id="four">第四个div</div>  
  11. </body>  
  12. </html>  


clear有四种

clear:none表示允许两边有浮动对象

clear:left表示不允许左边有浮动对象

clear:right表示不允许右边有浮动对象

clear:both表示不允许有浮动对象    单独成行


[css] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. //style.css  
  2. #first{  
  3.     width:300px;  
  4.     height:200px;  
  5.     background:red;  
  6.     float:left  
  7. }  
  8.   
  9. #second{  
  10.     width:300px;  
  11.     height:200px;  
  12.     background:pink;  
  13.     float:right  
  14. }  
  15.   
  16. #third{  
  17.     width:300px;  
  18.     height:200px;  
  19.     background:green;  
  20.     clear:left  
  21. }  
  22.   
  23.   
  24. #four{  
  25.     width:300px;  
  26.     height:200px;  
  27.     background:blue;  
  28.     float:right  
  29. }  

[css] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <html>  
  2. <head>  
  3.     <title>div的概念</title>  
  4.     <link rel = "stylesheet" href = "style.css" type = "css/style.css"/>  
  5. </head>  
  6. <body>  
  7.     <div id="first">第一个div</div>  
  8.     <div id="second">第二个div</div>  
  9.     <div id="third">第三个div</div>  
  10.     <div id="four">第四个div</div>  
  11. </body>  
  12. </html>  


有些情况还是比较特殊,有点弄不明白,要是有大神给知道就大好了


0 0
原创粉丝点击