javascript 溢出-y:滚动不适用于 chrome

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25807672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 05:03:47  来源:igfitidea点击:

overflow-y:scroll is not working for chrome

javascriptjqueryhtmlcssgoogle-chrome

提问by AKG

I am not getting a scroll-bar for box in chrome but getting in fire fox and internet explorer

我没有得到 chrome 中框的滚动条,而是进入了 fire fox 和 Internet Explorer

li.box{
    border-radius: 0px;
    padding:0;
    border: solid 1px #8c8d8e;
    overflow: hidden;
    overflow-y:scroll;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    background-color: #ffffff;
    opacity: 0.85;
}

this is JSFiddle link http://jsfiddle.net/wydsf2vk/

这是 JSFiddle 链接 http://jsfiddle.net/wydsf2vk/

回答by Mihir

Add height property to your css class, to display scrollbar you need to set fix height of your div.

将 height 属性添加到您的 css 类,要显示滚动条,您需要设置 div 的固定高度。

回答by mixophrygian

Are you by chance using a track pad instead of a mouse, on OSX? There's some quirk where the scrollbar will be hidden if you're using a track pad. Plug in a mouse and see if it appears.

您是否偶然在 OSX 上使用触控板而不是鼠标?如果您使用触控板,滚动条将被隐藏的地方有一些怪癖。插入鼠标,看看它是否出现。

回答by helcode

You are missing the heightCSS property. check snippet below.

您缺少heightCSS 属性。检查下面的片段。

.box {
    border-radius: 0px;
    padding:0;
    border: solid 1px #8c8d8e;
    overflow: hidden;
    overflow-y:scroll;
    height: 100px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    background-color: #ffffff;
    opacity: 0.85;
}
<div class="box">
  <p> Hello World 1 </p>
  <p> Hello World 2 </p>
  <p> Hello World 3 </p>
  <p> Hello World 4 </p>
  <p> Hello World 5 </p>
</div>

回答by Kenny

change your css:-

改变你的CSS:-

height:100px 
border-radius: 0px;
padding:0;
border: solid 1px #8c8d8e;
overflow: hidden;
overflow-y:scroll;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-color: #ffffff;
opacity: 0.85;

http://jsfiddle.net/wydsf2vk/2/

http://jsfiddle.net/wydsf2vk/2/

回答by kamatchikumar-India

Set max-height for that .box it will work

为那个 .box 设置 max-height 它将起作用

回答by Anshu Dwibhashi

I just checked your fiddle, that's happening because you've not added the overflow-y: scroll;property to the fiddle. It does work for my version (Chrome too).

我刚刚检查了您的小提琴,这是因为您尚未将该overflow-y: scroll;属性添加到小提琴中。它确实适用于我的版本(Chrome 也是如此)。

http://jsfiddle.net/y8jqsya4/

http://jsfiddle.net/y8jqsya4/