Safari中使用overflow-y:scroll时滚动条不可见

3
当一个使用了fixed属性,并且其样式为overflow: autoscroll的元素被包含在具备overflow: hidden样式的body元素内,在Safari 8.0.x中,滚动条是不可见的,但元素仍然可以滚动。而在Firefox 41.0.x中,滚动条是可见的。
这里有一个演示页面展示这种行为。
有没有办法让Safari中的滚动条保持可见?

*, *:before, *:after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    min-height: 100%;
    position: relative;
    margin: 0;
    padding: 0;
}

.sidebar {
    position: fixed;
    max-height: 100vh;
    min-height: 100vh;
    background: lightblue;
    width: 200px;
    top: 0;
    right: 0;
    padding: 20px;
    overflow-y: scroll;
}

.content-a {
    background: yellow;
    height: 900px;
}

.main {
    background: grey;
    min-height: 100vh;
    padding: 10px;
}

.content-b {
    height: 200px;
}

body, .main {
    overflow: hidden;
}
<div class="sidebar">
    <div class="content-a">
        content
    </div>
    bottom
</div>
<div class="main">
    <div class="content-b">
        content
    </div>
    bottom
</div>


请参见 https://dev59.com/zmsz5IYBdhLWcg3wfn-6 - Radio
我在我的Safari 8.0.8 (OSX Yosemite)中尝试了你的代码,它完美地运行了。 - Moïze
@Enzo 你能看到滚动条吗? - justinw
是的@Quoid,我已经把它放在右边了,这样我就可以滚动黄色侧边栏了。 - Moïze
@Enzo 奇怪,我在 Fiddle 或本地代码中看不到它。 - justinw
@Quoid 你有没有检查我下面的答案? - Moïze
1个回答

2
尝试对其进行样式化,并强制显示:
::-webkit-scrollbar {
    width: 10px;
}
 
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.4); 
    border-radius: 8px;
    -webkit-border-radius: 8px;
}
 
::-webkit-scrollbar-thumb {
    -webkit-border-radius: 10px;
    border-radius: 10px;
    background: rgba(100,100,100,0.8); 
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
}

工作编辑:

.sidebar::-webkit-scrollbar {
    display: inherit;
}

.sidebar:hover::-webkit-scrollbar {
    width: 10px;
}

.sidebar:hover::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.4); 
    border-radius: 8px;
    -webkit-border-radius: 8px;
}

.sidebar:hover::-webkit-scrollbar-thumb {
    -webkit-border-radius: 10px;
    border-radius: 10px;
    background: rgba(100,100,100,0.8); 
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
}

这类似于Radiuo上面发布的内容,只不过它是针对整个文档而不是element(这可能更好),但我不喜欢的是它不会像默认浏览器行为一样自动隐藏滚动条。 - justinw
那很奇怪,那是Safari的默认行为,也许这就是你能看到滚动条的原因。 - justinw

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接