学习DIVfloat在ff和ie下的布局区别

你对DIV float在ff和ie下的布局区别是否了解,这里和大家分享一下,DIV的起始标签和结束标签之间的所有内容都是用来构成这个块的,其中所包含元素的特性由DIV标签的属性来控制,或者是通过使用样式表格式化这个块来进行控制。

创新互联公司是一家专注于网站设计、网站制作与策划设计,梅江网站建设哪家好?创新互联公司做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:梅江等地区。梅江做网站价格咨询:028-86922220

学习DIV float在ff和ie下的布局区别

基本HTML代码
 

 
 
 
 
  1.  
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3.  
  4.  
  5.  
  6. DIVFloatSample title> </li> <li> </li> <li><styletypestyletype="text/css">DIV{margin:3px;}.d1{width:250px;min-height:20px;border:1pxsolid#00cc00;}  </li> <li> </li> <li>.d2{width:130px;min-height:40px;border:1pxsolid#0000cc;}  </li> <li> </li> <li>.d3{width:100px;min-height:40px;border:1pxsolid#cc0000;}  </li> <li> </li> <li> style> head> </li> <li> </li> <li><body><DIVclassDIVclass="d1"> </li> <li> </li> <li><DIVclassDIVclass="d2">   </li> <li> </li> <li> DIV><DIVclassDIVclass="d3">   </li> <li> </li> <li> DIV> DIV> body> </li> <li> </li> <li> html> </li> </ol></pre><p>以上代码显示的结果如下,很正常,结果相同。</p></p><p>下面会在这个基础上进行修改,修改的内容都在style中,其他代码就不再重复写了。</p><p>请注意,这里的Style中用到了min-height,这个和height是不同的,min-height指定了对象的一个最小高度,当对象的子内容高度超过这个最小高度是,这个对象会自动撑大。这是一个非常牛的style,可惜的是,在这个style和float这个同样牛的style一起使用的时候,就会出现各种问题。#p#</p><p>◆内部一个DIV修改成为float:left </p> <pre> <ol> <li>.d1{width:250px;min-height:20px;border:1pxsolid#00cc00;}  </li> <li> </li> <li>.d2{width:130px;min-height:40px;border:1pxsolid#0000cc;float:left;}  </li> <li> </li> <li>.d3{width:100px;min-height:40px;border:1pxsolid#cc0000;}  </li> </ol></pre><p>显示结果如下。</p><p>这个结果中,Firefox有点离谱了,两个框叠在一起也就罢了,为什么那个红框会变大捏?而且变的大小也很诡异,不知道是按照什么公式计算出来的。IE在这里的显示应当是附和标准的。</p><p>◆内部两个DIV都修改成为float:left </p> <pre> <ol> <li>.d1{width:250px;min-height:20px;border:1pxsolid#00cc00;}  </li> <li> </li> <li>.d2{width:130px;min-height:40px;border:1pxsolid#0000cc;float:left;}  </li> <li> </li> <li>.d3{width:100px;min-height:40px;border:1pxsolid#cc0000;float:left;}  </li> </ol></pre><p>显示结果如下。</p><p>在这种情况下,Firefox的结果尚能解释,可能是float把外层的DIV也作为内层float影响的范围,这样内层的就不会将外层的DIV撑大了。IE在这里出现了Margin失效的情况,可以解释为内层第二个float造成了影响。#p#</p><p>◆干脆把外层的DIV也修改成为float:left </p> <pre> <ol> <li>.d1{width:250px;min-height:20px;border:1pxsolid#00cc00;float:left;}  </li> <li> </li> <li>.d2{width:130px;min-height:40px;border:1pxsolid#0000cc;float:left;}  </li> <li> </li> <li>.d3{width:100px;min-height:40px;border:1pxsolid#cc0000;float:left;}  </li> </ol></pre><p>显示结果如下。</p><p>这种情况下,Firefox正常了,而IE延续了前面的不正常情况。</p><p>◆外层是float:left,内层最后一个不再float:left </p> <pre> <ol> <li>.d1{width:250px;min-height:20px;border:1pxsolid#00cc00;float:left;}  </li> <li> </li> <li>.d2{width:130px;min-height:40px;border:1pxsolid#0000cc;float:left;}  </li> <li> </li> <li>.d3{width:100px;min-height:40px;border:1pxsolid#cc0000;}  </li> </ol></pre><p>显示结果如下。</p></p><p>这和前面第一种加float:left的情况相同。#p#</p><p><strong>结论</strong></p><p>再重申一次,本文讨论的是一个比较高级的话题。如果在style中用height而不是min-height来设定高度,是不会出现以上这些问题的。不过,不用min-height就失去了DIV自动撑大这一个很有必要的特性。在min-height和float:left的情况下,没有一种完美的写法让Firefox和IE结果相同。不过仍然可以发现绕开的方法。进一步试验可以发现,margin遭到的影响在padding上比较好,所以最好是padding和margin都不用,或者只用padding。</p><p>两者相同的代码如下:</p> <pre> <ol> <li>DIV{padding:3px;}  </li> <li> </li> <li>.d1{width:250px;min-height:20px;border:1pxsolid#00cc00;float:left;}  </li> <li> </li> <li>.d2{width:130px;min-height:40px;border:1pxsolid#0000cc;float:left;}  </li> <li> </li> <li>.d3{width:100px;min-height:40px;border:1pxsolid#cc0000;float:left;}  </li> </ol></pre><p>显示结果如下。</p></p><p>当然所有这些情况也许是有合理解释的,说不定增加某一个style的设置,这些问题都迎刃而解了,不过目前我还没有找到这个设置。</p><p>【编辑推荐】</p> <ol> <li>DIV+CSS中常见十大错误总结</li> <li>DIV定位单元中三大元素的控制</li> <li>深入学习DIV+CSS之绝对定位和相对定位用法</li> <li>Div+CSS布局入门之写入整体层结构与CSS</li> <li>DIV+CSS开发过程中影响SEO的制作细节</li> </ol> <p> 当前题目:<a href="http://www.csdahua.cn/qtweb/news10/77610.html">学习DIVfloat在ff和ie下的布局区别</a> <br> 链接分享:<a href="http://www.csdahua.cn/qtweb/news10/77610.html">http://www.csdahua.cn/qtweb/news10/77610.html</a> </p> <p> 网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等 </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.csdahua.cn/" target="_blank">快上网</a> </p> </div> <div class="newsmorelb"> <p>成都快上网为您推荐相关内容</p> <ul> <li> <a href="/qtweb/news9/77609.html">域名购买时间有多久?(域名购买时间有多久的)</a> </li><li> <a href="/qtweb/news8/77608.html">日本云存储服务器租用怎么搭建网站</a> </li><li> <a href="/qtweb/news7/77607.html">安卓怎么反编译</a> </li><li> <a href="/qtweb/news6/77606.html">html中如何对话框</a> </li><li> <a href="/qtweb/news5/77605.html">Linux下开放TCP端口的安全性策略(linuxtcp端口)</a> </li><li> <a href="/qtweb/news4/77604.html">云主机安装系统</a> </li><li> <a href="/qtweb/news3/77603.html">密码让Redis连接变得更加安全默认用户名密码设置(redis连接默认用户名)</a> </li><li> <a href="/qtweb/news2/77602.html">如何进行百度推广优化,百度推广优化技巧分享</a> </li><li> <a href="/qtweb/news1/77601.html">c语言怎么输出矩阵</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/biaoqianseo/">标签优化知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news34/281634.html">如何远程重启服务器?(怎么重启远程服务器设备)</a> </li><li> <a class="text_overflow" href="/qtweb/news4/183504.html">使用Linux文件命令:简单又实用(linux的file命令)</a> </li><li> <a class="text_overflow" href="/qtweb/news11/504861.html">织梦怎么调用顶级栏目以及下面的二级栏目</a> </li><li> <a class="text_overflow" href="/qtweb/news48/268448.html">创新互联Python教程:python学习看哪些书</a> </li><li> <a class="text_overflow" href="/qtweb/news22/171922.html">c语言二维数组乘法怎么理解</a> </li><li> <a class="text_overflow" href="/qtweb/news47/320997.html">如何用html5写导航栏</a> </li><li> <a class="text_overflow" href="/qtweb/news31/250381.html">查看Redis数据库列表的方法(redis查看db列表)</a> </li><li> <a class="text_overflow" href="/qtweb/news31/68731.html">LinuxMD5加密字符串实现(linux对字符串进行md5)</a> </li><li> <a class="text_overflow" href="/qtweb/news0/50400.html">一个域名可以有多少子域名</a> </li><li> <a class="text_overflow" href="/qtweb/news44/95144.html">手机浏览器用的什么引擎</a> </li><li> <a class="text_overflow" href="/qtweb/news22/153272.html">c语言怎么表示幂</a> </li><li> <a class="text_overflow" href="/qtweb/news49/538499.html">c能开发网站吗_技能开发</a> </li><li> <a class="text_overflow" href="/qtweb/news23/485423.html">移动如何开通境外漫游功能</a> </li><li> <a class="text_overflow" href="/qtweb/news1/142851.html">Hadoop在MapReduce中使用压缩详解</a> </li><li> <a class="text_overflow" href="/qtweb/news7/265107.html">环境下应用Redis大数据量环境下的完美适用(redis适合在大数据量)</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/ggsj/" 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/qchs/" 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/xiaoguotu/" 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/huisuosj/" 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/shachuang/" 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/hntjbz/" 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/bolixiufu/" 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/shipaifang/" 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/zdfhw/" 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/snjbc/" 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/yhjdsj/" 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/ggtg/" 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/zbljbc/" 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/bangongkongjian/" 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/yangguangfang/" 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/chayisj/" target="_blank">茶艺设计</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="https://www.scvps.cn/" target="_blank">注册域名</a>    <a href="http://www.ynjbc.com/" target="_blank">兴发搬家</a>    <a href="http://www.cdkjz.cn/" target="_blank">成都网站设计</a>    <a href="http://www.ptjierui.cn/" target="_blank">ptjierui.cn</a>    <a href="http://www.amruizhi.cn/" target="_blank">amruizhi.cn</a>    <a href="https://www.cdxwcx.com/city/guanghan/" target="_blank">广汉网站建设</a>    <a href="http://www.cdhuace.com/" target="_blank">成都广告设计</a>    <a href="http://www.qltuopan.com/" target="_blank">成都木托盘</a>    <a href="http://www.bjjinzhi.cn/" target="_blank">晟和广告</a>    <a href="http://www.cdjierui.cn/" target="_blank">广安迈傲建站</a>    <a href="http://www.ycggtw.cn/" target="_blank">金羊影视传媒</a>    <a href="http://chengdu.cdcxhl.com/dingzhi/" target="_blank">定制网站</a>    <a href="https://www.cdcxhl.com/tuoguan/dianxin/" target="_blank">绵阳服务器托管</a>    <a href="https://www.cdxwcx.com/jifang/leshan.html" target="_blank">四川乐山服务器托管</a>    <a href="http://www.cdxwcx.cn/tuoguan/deyang.html" target="_blank">四川德阳主机托管</a>    <a href="https://www.scvps.cn/" target="_blank">云主机</a>    <a href="http://m.cdcxhl.cn/applets/ " target="_blank">成都小程序开发</a>    <a href="http://www.cdhuace.com/fuwu.html" target="_blank">成都名片印刷</a>    <a href="https://www.yanbangzhuzx.com/" target="_blank">研帮主</a>    <a href="https://www.cdcxhl.com/idc/gysx.html" target="_blank">贵阳托管服务器</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> 节约开发成本 <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'"> 立即开始2800定制网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 2800定制网站建设</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.csdahua.cn/" target="_blank">网站优化</a> <a href="http://www.csdahua.cn/" target="_blank">网络推广</a> <a href="http://www.csdahua.cn/" 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>