javascript - 当模态在 w3.css 中滚动时如何隐藏文档垂直滚动条?

标签 javascript html css w3.css

在w3.css中,当modal的内容足够大时,它会添加一个vertical scrollbar,这是很常见的,Okay。但是当主 HTML 文档有自己的滚动条时,两个滚动条会加在一起很丑。

enter image description here

请看下面的代码片段:

<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>

<div class="w3-container">
  <h2>Modal</h2>
  <p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p>
  <button onclick="document.getElementById('id01').style.display='block'" class="w3-btn w3-black">Open Modal</button>
  <p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p><p>The w3-modal class creates a dialog box/popup window that is displayed on top of the current page.</p>

  <div id="id01" class="w3-modal">
    <div class="w3-modal-content w3-card-4">
      <header class="w3-container w3-teal"> 
        <span onclick="document.getElementById('id01').style.display='none'" class="w3-button w3-display-topright">&times;</span>
        <h2>Header</h2>
      </header>
      <div class="w3-container">
        <p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p><p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p>
      </div>
      <footer class="w3-container w3-teal">
        <p>Footer</p>
      </footer>
    </div>
  </div>
</div>
          
</body>
</html>

能否请您指导我如何避免这种情况?

最佳答案

它对我有用。你可以删除滚动条的宽度,只需使用 ::-webkit-scrollbar 这个选择器

.w3-container{
  max-height: 500px;
  overflow: auto;
}
.w3-container::-webkit-scrollbar {
  width: 0;
}

关于javascript - 当模态在 w3.css 中滚动时如何隐藏文档垂直滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54618608/

相关文章:

javascript - 无法在 Angular $http 调用中获取由 Play 框架服务器设置的 cookie?

python - 在 Pelican 静态网站中托管原始 HTML 页面

javascript - 调整行中的谷歌地图高度动态

javascript - 我有 contenteditable div ,里面是一个不可编辑的跨度,如何通过跨度文本长按来标记 div 的文本

CSS 三 Angular 形在流体宽度事件选项卡上未正确对齐

Javascript - 在不同脚本中分隔变量

javascript - 是否可以将文本字段的值分配给单选按钮

javascript - 理解memo函数中的resolver(大前端q)

html - 悬停时更改按钮的图像?

css - 手写笔查找哈希名称