gpt4 book ai didi

html - 使用 flex 布局时 Chrome 滚动条损坏

转载 作者:行者123 更新时间:2023-12-05 05:06:46 27 4
gpt4 key购买 nike

我正在尝试在设置为 display: flex 的 div 上自定义 chrome 滚动条,滚动条坏了(见屏幕截图:屏幕截图显示上下双箭头,水平滚动条缺少拖动部分) .

不设置div(.container)为display:flex看起来还不错,但我的系统全是flex布局。

谁能帮忙解决这个问题?谢谢

<html>
<head>
<style>
::-webkit-scrollbar-button:horizontal:decrement {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAiSURBVHgBY2BEAxQJMKAJMKAJMKAJMOATgIkQMBTBooZfAH56AO2yINTrAAAAAElFTkSuQmCC);
}

::-webkit-scrollbar-button:horizontal:increment {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAgSURBVHgBY2BEA+QLMGAIMGAIMGAIMBAUIGQoZU5HAwB+ZgDtGYq3fgAAAABJRU5ErkJggg==);
}

::-webkit-scrollbar-button:vertical:increment {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAfSURBVHgBY2BEA7QTYIAChAoYH6EFxkeYwQBj0MelAH3GAO2C9+AaAAAAAElFTkSuQmCC)
}

::-webkit-scrollbar-button:vertical:decrement {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAgSURBVHgBY2BEAzQVYIAzYHwGGAvOZ4AyIXyECH1cCgB/GgDtpWTgqAAAAABJRU5ErkJggg==)
}

::-webkit-scrollbar {
height: 12px;
width: 12px
}

::-webkit-scrollbar-track {
background-color: rgba(222, 222, 222, 0.8);
}

::-webkit-scrollbar-button {
background-color: rgba(170, 170, 170, 0.8);
}

::-webkit-scrollbar-button:hover,
::-webkit-scrollbar-thumb {
background-color: rgba(138, 138, 138, 0.8);
}

::-webkit-scrollbar-corner {
background-color: rgba(222, 222, 222, 0.8);
}

::-webkit-scrollbar-button:horizontal:decrement,
::-webkit-scrollbar-button:horizontal:increment,
::-webkit-scrollbar-button:vertical:decrement,
::-webkit-scrollbar-button:vertical:increment {
height: 12px;
width: 12px;
background-position: 50%;
}

.container {
background: orange;
color: white;
overflow-x: scroll;
display: flex; /* this line breaks the scroll bars */
}
</style>
</head>
<body>
<div style="height:300px;width:300px;" class="container">
<div style="width: 800px; height: 800px">Hello</div>
</div>
</body>
</html>

问题:

problem

预期结果:

expectation

jsfiddle 上的相同代码 https://jsfiddle.net/Mingzilla/0asgu6j1/

最佳答案

要修复双箭头,请在您的 CSS 目标中包含 :single-button:

注意:页面不会向左或向右滚动,因为没有内容可以左右滚动。 Flexbox 将通过 flex 它来适应窗口中的所有内容,因此没有理由有滚动条句柄。 (将内部div改成min-width也可以强制出现水平滚动条)

<html>
<head>
<style>
::-webkit-scrollbar-button:single-button:horizontal:decrement {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAiSURBVHgBY2BEAxQJMKAJMKAJMKAJMOATgIkQMBTBooZfAH56AO2yINTrAAAAAElFTkSuQmCC);
}

::-webkit-scrollbar-button:single-button:horizontal:increment {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAgSURBVHgBY2BEA+QLMGAIMGAIMGAIMBAUIGQoZU5HAwB+ZgDtGYq3fgAAAABJRU5ErkJggg==);
}

::-webkit-scrollbar-button:single-button:vertical:increment {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAfSURBVHgBY2BEA7QTYIAChAoYH6EFxkeYwQBj0MelAH3GAO2C9+AaAAAAAElFTkSuQmCC)
}

::-webkit-scrollbar-button:single-button:vertical:decrement {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABlBMVEXM09b///8OmaLeAAAAAnRSTlP/AOW3MEoAAAAgSURBVHgBY2BEAzQVYIAzYHwGGAvOZ4AyIXyECH1cCgB/GgDtpWTgqAAAAABJRU5ErkJggg==)
}

::-webkit-scrollbar {
height: 12px;
width: 12px
}

::-webkit-scrollbar-track {
background-color: rgba(222, 222, 222, 0.8);
}

::-webkit-scrollbar-button:single-button {
background-color: rgba(170, 170, 170, 0.8);
}

::-webkit-scrollbar-button:single-button:hover,
::-webkit-scrollbar-thumb {
background-color: rgba(138, 138, 138, 0.8);
}

::-webkit-scrollbar-corner {
background-color: rgba(222, 222, 222, 0.8);
}

::-webkit-scrollbar-button:single-button:horizontal:decrement,
::-webkit-scrollbar-button:single-button:horizontal:increment,
::-webkit-scrollbar-button:single-button:vertical:decrement,
::-webkit-scrollbar-button:single-button:vertical:increment {
height: 12px;
width: 12px;
background-position: 50%;
}

.container {
background: orange;
color: white;
overflow-x: scroll;
display: flex; /* this line turns .container into flex layout */
}
</style>
</head>
<body>
<div style="height:300px;width:300px;" class="container">
<div style="min-width: 800px; height: 800px">Hello</div>
</div>
</body>
</html>

关于html - 使用 flex 布局时 Chrome 滚动条损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59634269/

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