我再次阅读了许多关于此主题的文章,但没有一个建议的解决方案可行。我现在有我的解决方案,但是,不知道它为什么会起作用,并希望得到一些见解。让div可滚动无滚动条
下面是该解决方案遍布SO: Hide scroll bar, but while still being able to scroll
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<div class="hidden-xs hidden-sm col-md-3" id="parent">
<div id="child">
Test text here
</div>
</div>
</body>
</html>
CSS
#parent {
padding: 0px;
border-width: 1px;
border-style: solid;
height: calc(100vh);
overflow: hidden;
}
#child {
width: 100%;
height: 100%;
overflow-y: scroll;
padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */
}
以上不为我工作的滚动条仍然可见。但是,我在页面上找到了一个父元素“box-sizing”的属性,当更改为“border-box”以外的任何内容时,滚动条消失并且滚动按预期工作。
根据浏览器,这个CSS来自bootstrap.Sass宝石。
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
我的两个问题是: 1)为什么会出现这种情况? 2)如何在我的CSS文件中关闭它?
尼斯的答案,它应该有一个'!important'只是为了确保它不会被覆盖,我认为他/她希望它是'内容box',而不是'边境-box'。 – MarioE
使用框大小:content-box;没有!重要的工作。 – Dercni