为什么空div用内容移动div?

时间:2016-09-13 19:32:28

标签: html css

我不明白为什么空div用内容移动div。



div {
  width: 100px;
  height: 100px;
  background-color: red;
  border: 2px solid #000;
  display: inline-block;
}

<div>a</div>
<div></div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

您需要向他们添加vertical-align

&#13;
&#13;
div {
  width: 100px;
  height: 100px;
  background-color: red;
  border: 2px solid #000;
  display: inline-block;
  vertical-align:top; /* <-- SEE THIS? */
}
&#13;
<div>a</div>
<div></div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

更改样式

    div { 
width: 100px; 
height: 100px; 
background-color: red; 
border: 2px solid #000; 
float:left; 
margin:0 2px;
 }

https://jsfiddle.net/anwnacc2/

请检查jsfiddle