谁赢了CSS的顶级/底部?
如果您的DIV位于“底部”之类的DIV,
<div id="box" style="position: absolute;width: 10px;height: 10px;bottom: 0px;"></div>
使用“ TOP”更改位置...
$('#box').css({'top':'0px'});
则 ?
我应该在设置顶部的同时以某种方式取消底部吗?
想法:
$('#box').css({'top':'0px','bottom','none'});
$('#box').css({'top':'0px','bottom',''});
以前从未想过
If you have a div that sits at the 'bottom' like so:
<div id="box" style="position: absolute;width: 10px;height: 10px;bottom: 0px;"></div>
and then if you were to change the position using 'top'...
$('#box').css({'top':'0px'});
what happens to the 'bottom' css command and what decides who (top or bottom) wins?
Should I cancel bottom somehow at the same time as setting top?
Ideas:
$('#box').css({'top':'0px','bottom','none'});
$('#box').css({'top':'0px','bottom',''});
It never occurred to me before
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CSS中各种场景中的宽度,高度和盒子偏移之间的相互作用都在规格的第10节。
由于您的元素是绝对定位的,请参阅 10.6。 4 ,说:
在您的情况下,因为设置了
top
的值,top
wins wins wins设置了一个值。请注意,设置
none
无法工作,因为它不是botton
的有效值,并且将“空字符串”恢复为默认值自动
,不会导致过度约束的值。The interactions between width, height, and box offsets in a variety of scenarios in CSS are all detailed in section 10 of the spec.
Since your element is absolutely positioned, refer to section 10.6.4, which says:
In your case, because the values are over-constrained once you set a value for
top
,top
wins.Note that setting
none
won't work because it's not a valid value forbottom
, and setting the empty string reverts it to its default value which for most if not all elements isauto
, which does not result in over-constrained values.top “赢”当所有三个
上
,底部
和height
都存在 - mdn :Top "wins" when all three of
top
,bottom
andheight
are present - MDN: