css - 在 overflow-y : scroll div 中定位绝对 div

标签 css scroll position overflow absolute

我有以下 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/

相关文章:

wordpress 中的 CSS 翻转 Logo

html - 如何轻松地在静态网站上发布书面更新?

jquery - 保持scrollTop,同时在当前查看的元素上方插入新部分(无故障)

CSS - 在固定定位元素下滚动内容?

c# - WPF 列表框在拖动时自动滚动

react-native - React Native Scrollview 中的scrollToEnd

css - 元件未固定到位

css - 表格中的渐变

javascript - css:在打印的 PDF 页面的 HTML 页脚中呈现页码(Chromium)

javascript - 移动没有 before 伪元素的 html block