网站建设资讯

NEWS

网站建设资讯

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> <br> 分享文章:CSS浮动float属性用法详解 <br> 链接地址:<a href="http://cdweb.net/article/coehegp.html">http://cdweb.net/article/coehegp.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/dgcjeep.html">html5动画js HTML5动画交互课件制作</a> </li><li> <a href="/article/dgcjssi.html">ios开发moya iOS开发模拟点击</a> </li><li> <a href="/article/dgcjeic.html">mysql怎么精确查找 mysql精确查询</a> </li><li> <a href="/article/dgcjesd.html">ios开发活体人脸识别 ios开发活体人脸识别软件</a> </li><li> <a href="/article/dgcjegi.html">html5主页代码 html主页源码</a> </li> </ul> </div> </div> </div> <footer> <div class="footop"> <div class="wrap"> <div class="bottomrpw"> <div class="erp arp"> <dl> <dt>ADDRESS</dt> <dd class="address"> <i class="icon"></i> <span class="word">成都市青羊区锦天国际1号楼1002室</span> </dd> </dl> </div> <div class="erp arp"> <dl> <dt>TEL</dt> <dd class="phonum"> <i class="icon"></i> <span class="word en"> <a href="tel:18980820575">18980820575</a> </span> </dd> </dl> </div> <div class="erp crp"> <dl> <dt>OTHER</dt> <dd> <a class="word get-quote">获得报价与方案</a> </dd> <dd> <a href="#" target="_blank" rel='nofollow' class="word" title="付款方式">付款方式</a> </dd> </dl> </div> <div class="erp code-rp"> <dl> <dt>Wechat</dt> <dd class="code-wrap"> <span class="code"> <img src="/Public/Home/images/qr-code.jpg" alt="快上网微信公众号" /> </span> </dd> </dl> </div> </div> </div> </div> <div class="footerbot"> <div class="friendlinks"> <div class="wrap"> <ul class="rpl"> <li><a href="http://www.scguanghua.com/" title="光华电信机房托管" target="_blank">光华电信机房托管</a></li><li><a href="http://www.atjyz.com/" title="新都网站建设" target="_blank">新都网站建设</a></li><li><a href="http://m.cdxwcx.com/seo.html" title="成都网站推广公司" target="_blank">成都网站推广公司</a></li><li><a href="http://www.wzjingkun.com/" title="发光广告字制作" target="_blank">发光广告字制作</a></li><li><a href="http://www.weiweichi.com/" title="四川柴油发电机" target="_blank">四川柴油发电机</a></li><li><a href="http://www.aywipdh.com/" title="成都玉柴发电机组" target="_blank">成都玉柴发电机组</a></li><li><a href="http://www.bzfdjgs.com/" title="巴中静音发电机" target="_blank">巴中静音发电机</a></li><li><a href="http://www.jnanhua.com/" title="led显示屏" target="_blank">led显示屏</a></li><li><a href="https://www.cdcxhl.com/xiaochengx.html" title="成都微信小程序" target="_blank">成都微信小程序</a></li><li><a href="http://seo.cdkjz.cn/seo/" title="网站推广" target="_blank">网站推广</a></li> </ul> </div> </div> <div class="wrap"> <div class="copyright"> <span class="en">©2007-2022</span> 成都快上网科技有限公司 <span class="en">ALL RIGHTS RESERVED.</span> <a rel="nofollow" href="http://www.miitbeian.gov.cn" target="_blank">蜀ICP备19037934号</a> </div> </div> </div> </footer> <div class="fcwrap"> <ul class="rpl clearfix"> <li class="phone"> <a rel="nofollow" target="_blank" href="tel:18980820575"> <i class="icon"></i> <strong>18980820575</strong> </a> </li> <li class="qq"> <a rel="nofollow" target="_blank" href="https://wpa.qq.com/msgrd?v=1&uin=244261566&site=qq&menu=yes"> <i class="icon"></i> <strong>244261566</strong> </a> </li> <li class="back-top"> <a href="javascript:void(0)" rel="nofollow" class="back-to-top"> <i class="icon"></i> <strong>回到顶部</strong> </a> </li> </ul> </div> <!--nav--> <div class="n-Wrap"> <div class="navBar visble show"> <div class="barlogo"> <a href="/" rel="nofollow"> <img src="/Public/Home/images/logo1.png" alt="成都做网站" /> <img src="/Public/Home/images/logo2.png" alt="成都网站设计" /> </a> </div> <div class="bmenu"> <i class="bar-top"><span></span></i> <i class="bar-cen"><span></span></i> <i class="bar-bom"><span></span></i> <i class="bar-left"><span></span></i> <i class="bar-right"><span></span></i> </div> </div> <section class="fixmenu"> <div class="close-bar"> <i class="bar-left"><span></span></i> <i class="bar-right"><span></span></i> </div> <nav class="smph"> <ul> <li class="index-hrefs on"><a href="http://www.cdweb.net/"><font>首页</font></a></li> <li><a href="/about/" rel="nofollow"><font>关于快上网</font></a></li> <li><a href="/service/" rel="nofollow"><font>服务范围</font></a></li> <li><a href="/case/" rel="nofollow"><font>案例展示</font></a></li> <li><a href="/solve/" rel="nofollow"><font>解决方案</font></a></li> <li><a href="/news/" rel="nofollow"><font>建站资讯</font></a></li> <li><a href="/contact/" rel="nofollow"><font>联系快上网</font></a></li> </ul> <div class="pwrap"> <span class="label">服务热线</span> <strong class="phone"><a href="tel:18980820575">18980820575</a></strong> </div> </nav> </section> </div> <!--end nav--> <script src="/Public/Home/js/hotcss.js"></script> <script type="text/javascript" src="/Public/Home/js/su_new.js"></script> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>