位置:绝对/固定更改显示属性以阻止 [英] Position:absolute / fixed changes display-property to block
本文介绍了位置:绝对/固定更改显示属性以阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天,我在工作中遇到一个有趣的问题. 当我用position:absolute或fixed设置一个内联元素的样式时,它的行为就像一个可以具有高度和with的块元素. 这是一个简短的示例:
Today I faced an interesting problem at work. When I style an inline-element with position:absolute or fixed it behaves like a block-element which can have a height and with. Here a short example:
span {
background: red;
height: 100px;
width: 100px;
}
span#absolute {
position: absolute;
top:30px;
left:30px;
}
<span>Inline</span>
<span id="absolute">Inline, too</span>
如您所见,两个跨度都有height
和width
(在内联元素上应该忽略).但是,在使用posision:absolute
时会应用它.
As you can see both spans have height
and width
(which should be ignored on inline-elemens). However it gets applied when using posision:absolute
.
所以我的问题是:第二个span
完全像display:block
一样,还是只是半块式行为?
So my question: Is the second span
behaving like display:block
completely or is it just a semi-block-behaviour?
推荐答案
查看全文