【问题标题】:Css overflow hides all content. Can't modify scrollbarsCss 溢出隐藏所有内容。无法修改滚动条
【发布时间】:2018-01-18 21:37:20
【问题描述】:

在我的代码中,我想要一些非常简单的东西。白色 div 应始终保持在水平中心,具有固定的 80vw 宽度和相对高度。垂直滚动条应该被隐藏并且垂直应该是自动的。出现了一个问题,因为水平滚动条不必要地显示。当我试图隐藏它时,整个内容都消失了,我无法找出问题所在。

var array = ['cat', 'dog', 'lion', 'tiger', 'snake']
for (var i = 0; i < 50; i++) {
    var random = Math.floor(Math.random() * (array.length));
    var n = array[random];
    var container = document.getElementById("container");
    container.innerHTML += '<div class="box">' + n + '</div>';
}
*{
outline:none;
transition:1s;

}
::-webkit-scrollbar:horizontal {
    display: none; 
}
html,body {
   position:absolute;
   left:0;
   top:0;
  margin:0;
  padding:0;
  width:100vw;

}

#container {

  position:absolute;
  top:0;
  left:0;
    height:auto;
  width:100vw;
    background-color: black;
	
}

.box {
  height: auto;
  width:80vw;
  margin-left:10vw;
  margin-top:10vh;
text-align:center;
vertical-align:middle;
font-size:calc(2vh + 2vw);
    background-color: white;
 
}
<html>
<head>
</head>
<body>
<div id="container"></div>
</body>
</html>

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    将 body 和 #container 宽度设置为 100% 应该可以解决问题

    【讨论】:

      【解决方案2】:

      您应该使用overflow 来允许或不允许滚动。 Here is a link看看怎么用。

      【讨论】:

        猜你喜欢
        • 2016-11-21
        • 2020-04-15
        • 1970-01-01
        • 1970-01-01
        • 2013-12-25
        • 2015-11-16
        • 2013-11-25
        • 2018-04-02
        • 2014-04-23
        相关资源
        最近更新 更多