微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

css – 在overflow-y中定位绝对div:滚动div

我有以下HTML

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.

和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将始终触发水平滚动条,因为它嵌套在可滚动块内.似乎现代浏览器不允许溢出-x:可见溢出-y:滚动.

原文地址:https://www.jb51.cc/css/427538.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。