gpt4 book ai didi

html - 宽度 :auto not working right for absolutely positioned div when scroll bar is present

转载 作者:太空宇宙 更新时间:2023-11-04 15:02:40 25 4
gpt4 key购买 nike

我有一个 div,其中包含一些绝对定位且具有明确高度的内容。当内容超出高度时,会出现一个滚动条,但它不符合我的 width:auto - 滚动条会覆盖内容。

例子:

<style>    
#main {
height: 100px;
border: 1px solid red;
overflow-y: auto;
position: absolute;
}

</style>

<div id='main'>
<div>test</div>
<div>test</div>
<div>testiiiiiiiing</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
</div>

这是怎么回事?这是浏览器错误吗?我怎样才能让它正确地尊重我的自动宽度?

最佳答案

可以使用overflow-y: scroll;

<style>

#main {
height: 100px;
border: 1px solid red;
overflow-y: auto;
position: absolute;
padding-right: 10px;
}
#a {}

</style>

CodePen

关于html - 宽度 :auto not working right for absolutely positioned div when scroll bar is present,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32148519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com