Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我有两个这样的div
<div class="parent"> <div class="child1"/> <div class="child2"/> </div>
child1 是位置:固定,我希望 child2 和 child1 并排。
我尝试过使用 inline-block,但这不起作用。我应该怎么办?
将应固定在容器中的元素括起来,将该容器设置为position:fixed,并相应地定位其子项。也许与float:left和float:right。
position:fixed
float:left
float:right
<div class="parent"> <div class="fixed-container"> <div class="child1"/> <div class="child2"/> </div> </div>
这是JSBIN
.child1 { position:fixed; } .child2{ float:right; margin-right:350px; }
也许它可以帮助你
一旦你把一些“固定”的东西放在流程之外,所以你可以绝对定位孩子 2,但它会相对于它所在的容器移动