【发布时间】:2015-09-03 14:59:33
【问题描述】:
我有以下 HTML:
<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 在里面并且有 max-height 和 overflow-y: 滚动。它的宽度与绿色的宽度相同。我试图绝对定位紫色 div,相对于黄色 div,但在绿色 div 之外 - 原因是我不希望黄色 div 有水平滚动条。这可能吗?
谢谢!
【问题讨论】:
-
也许您可以将 position: relative 放在 .container 上,而不是放在 .scrollable-block 上?你可以吗?
-
不,不幸的是,它需要与 .scrollable-block 相关。这是一个需要以这种方式运行的更复杂结构的缩小示例。
标签: css scroll position overflow absolute