使布局使用变换的坐标(CSS)
有没有办法使HTML/CSS在布局计算中使用转换的坐标?例如,如果我缩放DIV,我希望下一个Div能够自动从缩放的Div边界开始。
body {
padding:50px;
}
.a {
width:100px;
height:100px;
background-color:red;
transform:scale(1.2)
}
.b {
width:100px;
height:100px;
background-color:blue;
}
<div class="a">
hello
</div>
<div class="b">
world
</div>
Is there a way to make HTML/CSS to use the transformed coordinates in layout calculations? E.g. if I scale a div, I want the next div to automatically start on the scaled div's boundary.
body {
padding:50px;
}
.a {
width:100px;
height:100px;
background-color:red;
transform:scale(1.2)
}
.b {
width:100px;
height:100px;
background-color:blue;
}
<div class="a">
hello
</div>
<div class="b">
world
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这就是
变换
属性的目的。但是,
变换
(与许多其他属性一样)仅适用于元素及其后代而不是其兄弟姐妹。这是副设计。此外,诸如transform
之类的属性(和obacity
和其他)创建一个新的堆叠上下文,基本上弄乱了z- index订购。无论如何,要获得想要的东西,您可以使用其他方法:当您使用
1.2
的恒定尺度时,您可以使用它来计算的正底部边距.a to bump 兄弟姐妹像这样:
Yes, that's what the
transform
property is for.However,
transform
(like many other properties) only applies to an element and its descendants not its siblings. This is by-design. Furthermore, properties liketransform
(andopacity
, and others) create a new stacking context which basically messes-up z-index ordering.Anyway, to get what you want, you can use a different approach: as you're using a constant scale of
1.2
you can use that to calculate a positive bottom margin on.a
to bump siblings down, like so: