【发布时间】:2020-02-11 02:34:12
【问题描述】:
我有以下 HTML 和 CSS
section {
position: relative;
left: 50%;
transform: translateX(-50%);
max-width: 1147px;
padding-right: 0;
padding-left: 0;
}
.first_div {
display: flex;
flex-wrap: wrap;
width: 100%;
justify-content: space-between;
}
.first_child_div {
max-width: calc(60% - 9px);
width: 100%;
}
.second_child_div {
max-width: calc(34% - 9px);
width: 100%;
position: fixed;
}
<section>
<div class="first_div">
<div class="first_child_div">First child</div>
<div class="second_child_div">Second child</div>
</div>
</section>
而且模板看起来基本上是这样的。
模板
*已编辑 但是由于某种原因,当我上下滚动时,第二个子 div 仍然跟随页面的流动。但我希望它始终保持在同一个地方,即使页面滚动。有什么我想念的吗?感谢您的帮助。
【问题讨论】:
-
这里,我为你做了一个jsFiddlejsfiddle.net/tphyo6mj/7
-
我给你做了一个sn-p。请更改它以匹配您的问题
-
是因为这个
transform: translateX(-50%);在版块上。 stackoverflow.com/questions/35596475/… -
谢谢,让我头疼的是转换。
标签: html css css-position fixed