【发布时间】:2018-12-31 07:56:07
【问题描述】:
运行下面的 sn-p 以查看我想要实现的目标。
主要问题是:没有 JavaScript 是否有可能实现这一目标?
.container {
display: flex;
width: 400px;
height: 2000px;
background-color: #aaa;
}
.left {
width: 150px;
background-color: lightgreen;
}
.right {
width: 100%;
background-color: lightcoral;
}
.fixed {
position: fixed;
height: 100px;
width: 100%;
background-color: skyblue;
}
<div class="container">
<div class="left">
My width can change anytime.
</div>
<div class="right">
<div class="fixed">
I'm fixed. Scroll the page to verify.<br /> I want to be the same width as my red parent.<br /> Any tips?
</div>
</div>
</div>
【问题讨论】:
-
我的回答很快,而且只适用于某些情况......顺便说一句,为什么不考虑粘性位置?您将获得与固定效果几乎相同的效果
-
这里是一个例子:jsfiddle.net/ywavjqpd
-
一定要关注欺骗链接的链接帖子,因为在某些情况下可以让它发挥作用。
标签: css flexbox css-position