我希望元素保留在其父母(orange
)容器的absolute right position
中。但是如果使用水平滾動,它不起作用。我究竟做錯了什麼?如何保持元素總是在正確的位置?父母滾動時的位置絕對正確
* {
box-sizing: border-box;
}
.outer {
position: relative;
padding: 10px;
border: solid 1px black;
background-color: orange;
width: 400px;
height: 200px;
overflow: scroll;
}
.stay-right {
position: absolute;
right: 0px;
top: 0px;
border: solid 1px black;
background-color: green;
width: 20px;
height: 100%;
}
.inner {
width: 600px;
}
<div class="outer">
<div class="stay-right"></div>
<div class="inner">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
</div>
是否有一個原因,你不僅僅是應用'overflow:scroll;'到'.inner'? – schrej
@schrej很好的問題。是的,原因是外部可調整大小... – caramba