gpt4 book ai didi

html - 如果垂直滚动条可见,Chrome 中的 Flexbox 元素高度错误

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

似乎谷歌浏览器在首次呈现 Flexbox 容器时没有考虑 Flex 元素的垂直滚动条。

这是页面刚加载后的样子:

Wrong

这是稍微改变容器宽度后的样子。

Good

IE10、IE11 和 FF 确实考虑了滚动条。

这是 codepen .

HTML:

<div class="subj">
<div>
Lorem ipsum dolor sit amet, ...
</div>
<div>
Lorem ipsuxm dolor sit amet, ...
</div>
<div>
Lorem ipsum dolor sit amet, ...
Lorem ipsum dolor sit amet, ...
</div>
</div>

CSS:

* {
margin: 0;
padding: 0;
}

html,
body {
width: 100%;
height: 100%;
}

.subj {
width: 400px;
height: 300px;
display: flex;
flex-direction: column;
justify-content: flex-start;
}

.subj > :nth-child(1) {
background: #f88;
flex: 0 0 auto;
}
.subj > :nth-child(2) {
background: #8f8;
flex: 0 0 auto;
overflow: auto;
white-space: nowrap;
position: relative;
border: 5px solid #f8f;
}
.subj > :nth-child(3) {
background: #88f;
flex: 1 1 auto;
overflow: auto;
}

有没有办法让 Chrome 尊重滚动条?

最佳答案

不幸的是,我不知道是什么导致了这个问题。

但一个简单的解决方法是设置正确的高度。

关于subj css规则

.subj > :nth-child(2)

添加:

overflow:scroll;

关于html - 如果垂直滚动条可见,Chrome 中的 Flexbox 元素高度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29075836/

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