CSS浮动float属性用法详解

你对CSS浮动float属性的使用是否了解,这里和大家分享一下,我们常常通过对div元素应用float浮动来进行布局,不但对整个版式进行规划,也可以对一些基本元素如导航等进行排列。

DIV CSS布局:CSS浮动float属性详解

在传统的表格布局中,我们对表格应该对齐方式对实现了对布局的应用,而应用Web标准构建网页以后,float浮动属性是布局中非常重要的属性,我们常常通过对div元素应用float浮动来进行布局,不但对整个版式进行规划,也可以对一些基本元素如导航等进行排列。

float属性基本释义:

  该属性的值指出了对象是否及如何浮动。当该属性不等于none引起对象浮动时,对象将被视作块对象(block-level),即display属性等于block。也就是说,浮动对象的display特性将被忽略。

float属性的参数:

  none:对象不浮动

  left:对象浮在左边

  right:对象浮在右边

  下面我们通过一些测试来了解可能出现的一些情况,如果float取值为none则不会发生任何浮动,块元素独占一行,紧随其后的块元素将在新行中显示,如下图:

 我们看下面的运行效果:

SourceCodetoRun

 
 
 
 
  1. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2.  
  3.  
  4. content="text/html;charset=gb2312"/> 
  5. 52CSS title> </li> <li><styletypestyletype="text/css"> </li> <li>#content_a{width:200px;height:80px;border:1pxsolid#000;</li> <li>margin:10px;background:#ccc;}  </li> <li>#content_b{width:200px;height:80px;border:1pxsolid#000;</li> <li>margin:10px;background:#999;}  </li> <li> style> </li> <li> head> </li> <li><body> </li> <li><dividdivid="content_a">52CSS.com这是第一个DIV div> </li> <li><dividdivid="content_b">52CSS.com这是第二个DIV div> </li> <li> body> </li> <li> html> </li> <li> </li> </ol></pre><p>[可先修改部分代码再运行查看效果]#p#</p><p>我们对content_a应用向左的浮动。而content_b不应用任何浮动。</p><p>SourceCodetoRun</p><pre> <ol> <li></li> <li>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> </li> <li><htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> </li> <li><head> </li> <li><metahttp-equivmetahttp-equiv="Content-Type"content="text/html;</li> <li>charset=gb2312"/> </li> <li><title>52CSS title> </li> <li><styletypestyletype="text/css"> </li> <li>#content_a{width:200px;height:80px;float:left;border:1pxsolid#000;</li> <li>margin:10px;background:#ccc;}  </li> <li>#content_b{width:200px;height:80px;border:1pxsolid#000;margin:10px;</li> <li>background:#999;}  </li> <li> style> </li> <li> head> </li> <li><body> </li> <li><dividdivid="content_a">52CSS.com这是第一个DIV向左浮动 div> </li> <li><dividdivid="content_b">52CSS.com这是第二个DIV不应用浮动 div> </li> <li> body> </li> <li> html> </li> <li> </li> </ol></pre><p> [可先修改部分代码再运行查看效果]</p><p>  我们看在IE6中的效果:</p><p><p>  我们看在Firefox中的效果:</p><p><p>  在IE中,对content_a应用向左的浮动后,content_a向左浮动,content_b在水平方向仅跟着它的后面。</p><p>  在Firefox中,对content_a应用向左的浮动后,content_b在水平方向容器不可见,只留下了文字。这是由于未清除浮动所造成的现象,关于清除浮动,可以参考这里:http://www.52css.com/article.asp?id=132这就是IE与Firefox对此种情况的不同解决,我们在实际布局中,应该避免这样的情况发生。</p><p> 【编辑推荐】</p><ol> <li>CSS Sprites对CSS布局的意义</li><li>如何使用CSS框架这把双刃剑?</li><li>CSS中font-size属性值四大种类</li><li>解析四大CSS属性值选择器用法</li><li>专家推荐 DIV CSS表单布局的五个小技巧</li></ol> <p> 文章标题:<a href="http://www.kswsj.com/qtweb/news25/451575.html">CSS浮动float属性用法详解</a> <br> 分享网址:<a href="http://www.kswsj.com/qtweb/news25/451575.html">http://www.kswsj.com/qtweb/news25/451575.html</a> </p> <p> 网站建设、网络推广公司-成都快上网,一家网站设计、网站制作公司;服务项目有等 </p> <p class="adpic"> <a href="https://www.cdcxhl.com/service/ad.html" target="_blank" class="ad">广告</a> <a href="" target="_blank" class="adimg"><img src=""></a> </p> <p class="copy"> 声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: <a href="http://www.kswsj.com/" target="_blank">成都快上网</a> </p> </div> <div class="newsmorelb"> <p>成都快上网科技猜您喜欢</p> <ul> <li> <a href="/qtweb/news24/451574.html">Oracle11中如何安全删除表</a> </li><li> <a href="/qtweb/news23/451573.html">Redis快速清理数据FLUSHALL指令(redis 清除数据命令)</a> </li><li> <a href="/qtweb/news22/451572.html">阿里云RDS数据库日志,数据保障与安全性的保证。(阿里云rds数据库日志)</a> </li><li> <a href="/qtweb/news21/451571.html">虚拟主机空间不够怎么解决呢</a> </li><li> <a href="/qtweb/news20/451570.html">Redis精确掌握深入浅出概念图解(redis概念图)</a> </li><li> <a href="/qtweb/news19/451569.html">vps宽带连接找不到怎么解决</a> </li><li> <a href="/qtweb/news18/451568.html">长春站谁建的?</a> </li><li> <a href="/qtweb/news17/451567.html">有关介绍ADO.NET数据集视频</a> </li><li> <a href="/qtweb/news16/451566.html">@灵码开盲盒</a> </li> </ul> </div> </div> <div class="col-lg-3 noneb"> <div class="bkright" style="margin-top: 0"> <p><a href="https://www.cdcxhl.com/news//">解决方案知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news35/501085.html">如何彻底卸载Linux系统中的GCC及G编译器?(linux卸载gccg)</a> </li><li> <a class="text_overflow" href="/qtweb/news37/489887.html">想学编程?这样开始</a> </li><li> <a class="text_overflow" href="/qtweb/news34/167784.html">深入探究kubernetes的作用领域,它对现代技术发展带来了哪些影响?</a> </li><li> <a class="text_overflow" href="/qtweb/news20/62720.html">美国13个根服务器指什么?在美国的服务器</a> </li><li> <a class="text_overflow" href="/qtweb/news27/73077.html">Linux恢复已删除的文件夹(linux删除文件夹恢复)</a> </li><li> <a class="text_overflow" href="/qtweb/news26/246226.html">网上卖的无限流量路由器真的假的啊</a> </li><li> <a class="text_overflow" href="/qtweb/news3/372153.html">做网站选香港服务器的优势在哪里</a> </li><li> <a class="text_overflow" href="/qtweb/news15/534365.html">win7防火墙怎么下载?windows防火墙下载</a> </li><li> <a class="text_overflow" href="/qtweb/news6/105556.html">在哪可以买到游戏的服务器?哪里有服务器买</a> </li><li> <a class="text_overflow" href="/qtweb/news45/37945.html">供应商与客户互利原则?(如何成为客户优质的供应商)</a> </li><li> <a class="text_overflow" href="/qtweb/news45/191495.html">MSSQL事物处理技巧之存储过程(mssql存储过程事物)</a> </li><li> <a class="text_overflow" href="/qtweb/news24/478124.html">利用Linux创建目录的方法(linux创建目录)</a> </li><li> <a class="text_overflow" href="/qtweb/news8/320808.html">Debian登录ssh很慢怎么办?debian ssh登录慢的解决办法</a> </li><li> <a class="text_overflow" href="/qtweb/news3/461003.html">快速高效!大数据管道助力数据库传输(大数据管道传输数据库)</a> </li><li> <a class="text_overflow" href="/qtweb/news3/158003.html">向量怎么求?(向量怎么求模)</a> </li> </ul> </div> <div class="bkright tag"> <p><a href="https://www.cdcxhl.com/hangye/" target="_blank">同城分类信息</a></p> <ul> <li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/gaokongche/" target="_blank">高空作业车租赁</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/menchuang/" target="_blank">门窗定制</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/chalousj/" target="_blank">茶楼设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/hgdsj/" target="_blank">火锅店设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/pe/" target="_blank">PE包装袋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/lajitong/" target="_blank">垃圾桶</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shipenji/" target="_blank">湿喷机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/dibang/" target="_blank">地磅秤</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/jiaquan/" target="_blank">除甲醛</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/hntjbg/" target="_blank">混凝土搅拌罐</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/boligeduan/" target="_blank">玻璃隔断</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shiliangting/" target="_blank">石凉亭</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/hntjbj/" target="_blank">混凝土搅拌机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zufadianji/" target="_blank">发电机租赁</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/caihui/" target="_blank">墙体彩绘</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zsljbc/" target="_blank">自上料搅拌车</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="http://chengdu.cdcxhl.cn/H5/" target="_blank">成都响应式网站建设公司</a>    <a href="http://www.qltuopan.com/" target="_blank">成都木托盘</a>    <a href="https://www.cdcxhl.com/cqtuoguan.html" target="_blank">重庆服务器托管</a>    <a href="http://www.dmvi.cn/" target="_blank">成都广告制作</a>    <a href="https://www.cdxwcx.com/" target="_blank">网络营销推广</a>    <a href="https://www.cdxwcx.com/jifang/mianyang.html" target="_blank">绵阳电信机房</a>    <a href="https://www.cdxwcx.com/jifang/mianyang.html" target="_blank">绵阳服务器托管</a>    <a href="https://www.xwcx.net/jigui.html" target="_blank">成都机房机柜租用</a>    <a href="http://m.cdcxhl.com/" target="_blank">成都做网站</a>    <a href="https://www.cdxwcx.com/wangzhan/applet.html" target="_blank">微信小程序开发</a>    <a href="https://www.cdxwcx.com/jifang/mianyang.html" target="_blank">绵阳托管服务器</a>    <a href="http://www.bjjxxy.cn/" target="_blank">圣月阀门</a>    <a href="http://m.cdcxhl.com/liucheng.html" target="_blank">成都网站建设流程</a>    <a href="http://www.cdxwcx.cn/tuoguan/meishan.html" target="_blank">眉山电信机房</a>    <a href="http://www.cdxwcx.cn/tuoguan/zigong.html" target="_blank">自贡主机托管</a>    <a href="http://www.lswzjz.com/" target="_blank">乐山网站建设</a>    <a href="http://www.kratc.com/" target="_blank">成都开元</a>    <a href="http://chengdu.cdcxhl.cn/seo/ " target="_blank">成都网站优化</a>    <a href="http://www.024fuxl.com/" target="_blank">成都学生服定制</a>    <a href="https://www.cdxwcx.com/tuiguang/" target="_blank">成都SEO优化</a>     </div> </div> <footer> <div class="carousel-inner footjz"> <div class="container"> <i class="icon iconfont zbw"></i> 品质网站建设 <i class="icon iconfont"></i> 多平台展现 <i class="icon iconfont"></i> 600元建站 <i class="icon iconfont"></i> 高效快速 <i class="icon iconfont"></i> 专业用心服务 <button type="button" class="btn btn-default btn-lg" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 立即开始600元网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 600元企业网站建设</button> </div> </div> <div class="carousel-inner bqsy"> <div class="container"> <div class="lxfs"> <h4 class="yutelnone">028-86922220 13518219792</h4> <h4 class="yutelblock"><a href="tel:02886922220">028-86922220</a> <a href="tel:13518219792">13518219792</a></h4> <a class="btn btn-default" href="tencent://message/?uin=532337155&Site=&Menu=yes" role="button">网站建设<span>QQ</span>:532337155</a> <a class="btn btn-default" href="tencent://message/?uin=631063699&Site=&Menu=yes" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" role="button">网站制作<span>QQ</span>:532337155</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=631063699&version=1&src_type=web&web_src=oicqzone.com" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn-default nonea" href="tencent://message/?uin=1683211881&Site=&Menu=yes" role="button">售后QQ:1683211881</a> <div class="dz">成都快上网专注: <a href="http://www.kswsj.com/" target="_blank">成都网站制作</a> <a href="http://www.kswsj.com/" target="_blank">网站设计</a> <a href="http://www.kswsj.com/" target="_blank">成都网站建设</a> <address>地址:成都太升南路288号锦天国际A幢10楼</address> </div> </div> <div class="bzdh dz"><img src="https://www.cdcxhl.com/imges/bottom_logo.png" alt="创新互联"> <p><a href="https://www.cdcxhl.com/menu.html" target="_blank">成都创新互联科技有限公司</a><br> Tel:028-86922220(7x24h)</p></div> </div> </div> </footer> </body> </html> <script> $.getJSON ("../../qtwebpic.txt", function (data) { var jsonContent = { "featured":data } var random = jsonContent.featured[Math.floor(Math.random() * jsonContent.featured.length)]; $(".adpic .adimg").attr("href",random.link) $(".adpic img").attr("src",random.pic); }) </script>