1
我想要创建一个固定的元素,它将在向下滚动时位于同一位置,但在调整窗口大小时,也会在x轴上与另一个div相对。与另一个div相关的固定div
#blackbox {
width: 500px;
height: 2000px;
background-color: black;
color: white;
margin: 0 auto;
}
#floater {
width: 150px;
background-color: blue;
color: white;
position: fixed;
top: 50px;
right: 120px;
/* want here 10px on right from black box */
}
<html>
<div id="blackbox">
This is blackbox
<br> This is blackbox
<br> This is blackbox
<br> This is blackbox
<br> This is blackbox
<br>
</div>
<div id="floater">
Always 10px from black box
</div>
</html>
编辑: 我找到了解决方案here。
#floater {
left: calc(50% + 510px); /* 50% + blackbox width + wanted 10px space *.
}
你能告诉我们你什么工作? –