请问为什么给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>
正在回答
垂直方向上的相邻元素之间的margin-top和margin-bottom是取较大值,
但水平方向上相邻元素之间的margin-left和margin-right是相加的;
有没有浮动都是这样的。
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧