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

本文介绍了CSS中float属性的三种设置方式及其对div布局的影响,并详细解释了clear属性的四种用法,帮助读者更好地掌握网页布局技巧。

http://blog.youkuaiyun.com/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>  


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


``` <div style="width: 110%;height: 220%;background-color: white;float: left;margin-top: 40px;margin-left: -660px;border-radius: 10px"> <div style="width: 5px;height: 25px;background-color: #1f78ff;margin-top: 22px;margin-left: 10px;border-radius: 10px;float: left"> </div> <div style="float: left;margin-top: 20px;font-size: 20px;font-weight: bold;width: 40%;"> 今日有效单量:{{ userinfo.today_order || '0' }}单 </div> <div style=" float: right;font-size: 14px;color: gray;padding-top: 20px;padding-right: 20px">更新时间:{{ userinfo.nowtime }} <button @click="showdrawer" type="primary" style="color: rgb(64,158,255);background-color: white;border: none">数据表格 ></button> </div> <div style="clear: both"></div> <div style="float: left;padding-top: 10px;padding-left: 10px;"> 日期A:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalBa }}</span>单 日期B:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalAa }}</span>单 升幅: <span style="font-weight: bold">{{ this.totalBa - this.totalAa }}</span>单 </div> <div style="clear: both"></div> <div style="float: left;padding-left: 8px;padding-top: 20px"> 对比日期A: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 106px;margin-top: -26px"> <el-date-picker value-format="yyyy-MM-dd" style="width: 140px;" v-model="timeA" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: left;padding-left: 260px;margin-top: -32px;"> 对比日期B: </div> <div style="clear: both"></div> <div style="float: left;padding-left: 360px;margin-top: -36px;"> <el-date-picker value-format="yyyy-MM-dd" style="width: 150px;" v-model="timeB" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="float: right;margin-top: -36px;margin-right: 350px;"> <el-select style="width: 50%;" v-model="current_time" placeholder="当前对比" @change="getOrderChart"> <el-option v-for="item in option_time" :label=item.label :value="item.value "> </el-option> </el-select> </div> <div style="clear: both"></div> </div>```窗口缩小里面的今日有效单量:0单日期A:0单 日期B:0单 升幅: 0单 2025-03-16 对比日期B: 2025-03-17 当前对比 位置发生错乱看不到了,要求是不要新代码在我的代码基础上修改,达到窗口缩小后依然全可以看到
最新发布
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值