我有以下 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: scroll。它的宽度应与绿色宽度相同。我试图相对于黄色 div 绝对定位紫色 div,但在绿色 div 之外 - 原因是我不希望黄色 div 具有水平滚动条。这可能吗?
谢谢!
最佳答案
您不能用当前的标记来做到这一点。 absolute-div 将始终触发水平滚动条,因为它嵌套在 scrollable-block 内。似乎现代浏览器不允许 overflow-x:visible 和 overflow-y:scroll。
关于css - 在 overflow-y : scroll div 中定位绝对 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20098907/