猿问

为什么没有发生外边距叠加呢?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<style>

 a[title]{

border-bottom:1px dotted #999;

}

a[title]:hover, a[title]:focus{

cursor:help;

}

.box1{ background:#234;

border:1px solid 

#000;

height:50px;

width:50px;

margin:30px;

}

.box2{ background:#F00;

height:50px;

width:50px;

margin:20px;}

</style>

</head>


<body>

<p>The term <a href="#" title="self-contained underwater breathing apparatus">SCUBA </a>  is an aconym rather than an abbreviation as it is as a word.</p>

<div class="box1"><div class="box2"></div></div>


</body>

</html>


图像789
浏览 1474回答 3
3回答

qq_青枣工作室_0

因为你设置了border。W3C原文:Two margins are adjoining if and only if:both belong to in-flow block-level boxes that participate in the same block formatting contextno line boxes, no clearance, no padding and no border separate them (Note that certain zero-height line boxes (see 9.4.2) are ignored for this purpose.)both belong to vertically-adjacent box edges两个外边距仅在以下情况下叠加:都属于常规文档流(in-flow)中的 block-level boxes,而且处于同一个块级格式化上下文没有 line boxs 、clearance、padding 和 border 将其分隔(certain zero-height line boxes 除外)都属于垂直方向上相邻的盒子的相邻外边距

柠檬酸钠

因为div2在div1里面,而margin是外边距,这没法叠加啊

老猿

你把box2的margin去掉就重叠了!
随时随地看视频慕课网APP
我要回答