谁赢了CSS的顶级/底部?

发布于 2025-02-14 01:34:52 字数 416 浏览 3 评论 0原文

如果您的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深爱成瘾 2025-02-21 01:34:52

CSS中各种场景中的宽度,高度和盒子偏移之间的相互作用都在规格的第10节

由于您的元素是绝对定位的,请参阅 10.6。 4 ,说:

对于绝对定位的元素,垂直尺寸的使用值必须满足此约束:

'top' +'保证 - 边框 +“边框宽度' +“填充” +“高度” +“高度” +'padding bottom' +'border-tover-topom-witth' +'margin' +'底部'=包含块的高度

如果所有三个“顶部”,“高度”和“底部”是自动的,则将“顶部”设置为静态位置,并在下面使用规则第三。

如果这三个都不是“自动”:如果“保证金顶”和“ margin bottom”都是“自动”,则在两个余量获得相等值的额外约束下求解方程。如果“保证金顶”或“边距底部”是“自动”,请求解该值的方程式。如果值过度约束,请忽略“底部”的值并求解该值。

在您的情况下,因为设置了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:

For absolutely positioned elements, the used values of the vertical dimensions must satisfy this constraint:

'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' + 'bottom' = height of containing block

If all three of 'top', 'height', and 'bottom' are auto, set 'top' to the static position and apply rule number three below.

If none of the three are 'auto': If both 'margin-top' and 'margin-bottom' are 'auto', solve the equation under the extra constraint that the two margins get equal values. If one of 'margin-top' or 'margin-bottom' is 'auto', solve the equation for that value. If the values are over-constrained, ignore the value for 'bottom' and solve for that value.

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 for bottom, and setting the empty string reverts it to its default value which for most if not all elements is auto, which does not result in over-constrained values.

自找没趣 2025-02-21 01:34:52

top “赢”当所有三个底部height都存在 - mdn

...顶部属性覆盖了底部属性,因此,如果顶部不是自动的,则底部的计算值是顶部计算值的负数。

Top "wins" when all three of top, bottom and height are present - MDN:

...the top property overrides the bottom property, so if top is not auto, the computed value of bottom is the negative of the computed value of top.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文