我有以下HTML:位置絕對格:滾動DIV
<div class="container">
<div class="scrollable-block">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<div class="absolute-div"></div>
</div>
和CSS:
.container {
width: 200px;
height: 300px;
background: green;
}
.scrollable-block {
width: 200px;
max-height: 250px;
overflow: scroll;
position: relative;
}
.absolute-div {
width: 20px;
height: 20px;
background: purple;
position: absolute;
top: 0;
right: -10px;
}
這裏是一個現場演示:http://jsfiddle.net/BYTam/1/
綠色的div是容器,並有一個固定的寬度。黃色div在它內部,並具有最大高度和溢出y:滾動。它的意思是與綠色的寬度相同。我試圖將紫色div相對於黃色div絕對定位,但是在綠色div之外 - 原因是我不希望黃色div具有水平滾動條。這甚至有可能嗎?
謝謝!
也許你可以把位置:相對.container而不是.scrollable塊?你覺得可以嗎? –
不,它需要與.scrollable-block相關。這是一個更復雜的結構的例子,需要以這種方式行事。 –