请问为什么给div元素设置float之后两个浮动div的margin会叠加而不是取大值了呢

请问为什么给div元素设置float之后两个浮动div的margin会叠加而不是取大值了呢

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8">

<title>CSS布局</title>

<style type="text/css">

/*此处写代码*/

*{margin:0px;padding:0px;}

.above{width:800px;}

.header{text-align:center;}

.img1,.img2{width:350px;float:left;margin:11px;}

img{width:350px;}

</style>

</head>

<body>

<!-- 此处写代码 -->

<div class="above">

  

  <div class="header"><h4>ENJOY YOUR LIVE</h4></div>

   <div class="img1"><dl>

       <dt>

           <img src="http://img1.sycdn.imooc.com/climg//58f829090001a4b504260240.jpg">

       </dt>

       <dd> As the world’s fourth biggest smartphone vendor,Xiaomi has raised over US$5.4 billion through the long-awaited initial public offering under the symbol 1810.</dd>

   </dl></div>

   <div class="img2"><dl>

       <dt>

           <img src="http://img1.sycdn.imooc.com/climg//58f829090001a4b504260240.jpg">

       </dt>

       <dd> As the world’s fourth biggest smartphone vendor,Xiaomi has raised over US$5.4 billion through the long-awaited initial public offering under the symbol 1810.</dd>

   </dl></div>

</div>

</body>

</html>


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

垂直方向上的相邻元素之间的margin-top和margin-bottom是取较大值,

但水平方向上相邻元素之间的margin-left和margin-right是相加的;

有没有浮动都是这样的。

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码