[英]space between an inline-block element and a block element
What is that space between these two divs? 这两个div之间的空间是多少? I even removed the white space in html. 我什至删除了html中的空白。
<div id="asd"></div><div id="psd"></div>
http://jsfiddle.net/9thpuvwa/ http://jsfiddle.net/9thpuvwa/
Now, if the first div (asd) has some text in it, the space is gone; 现在,如果第一个div(asd)中包含一些文本,则空格消失了; WHAT? 什么?
<div id="asd">a</div><div id="psd"></div>
http://jsfiddle.net/kadb1d3s/ http://jsfiddle.net/kadb1d3s/
(I'm trying to understand my prev question ) (我试图理解我的上一个问题 )
CSS 的CSS
#asd {
background-color: blue;
display: inline-block;
width: 200px;
height: 200px;
}
#psd {
background-color: red;
width: 200px;
height: 200px;
}
The question: Where that space is coming from? 问题:空间来自哪里?
This appears to be caused by the vertical alignment. 这似乎是由垂直对齐引起的。 Where it's set to inline-block
, by default the vertical alignment is set to baseline
, which is slightly higher raised (probably to account for characters like 'y' and 'g' which dip below the line). 在将其设置为inline-block
的情况下,默认情况下,垂直对齐方式设置为baseline
,它的凸起度略高(可能考虑到字符“ y”和“ g”,它们位于行下方)。
vertical-align
of top
seems to fix it: top
vertical-align
似乎可以解决此问题:
#asd {
...
vertical-align: top;
}
Where that space is coming from? 该空间来自哪里?
From the inline-block
element being aligned to the baseline
of the “line” it is displayed on. 从将inline-block
元素对齐到“行”的baseline
,将其显示在上面。
Add vertical-align:bottom
(or text-bottom
, or middle
, or top
, …) to it, and the space will be gone: http://jsfiddle.net/9thpuvwa/2/ 向其添加vertical-align:bottom
(或text-bottom
, middle
或top
…),然后空格将消失: http : //jsfiddle.net/9thpuvwa/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.