html - CSS 网格滚动问题 : right-side padding and border "overlapping" content

标签 html css css-grid

我不明白这种行为。这是一个错误吗?我必须怎么做才能使正确的填充和边框位于(橙色)内容之外?

更新:我想要滚动。问题是右边的填充和边框没有被推到右边,而是与(橙色)内容重叠。

enter image description here

<!doctype html>
<html>
<title>Test</title>
<head>
<meta http-equiv='content-type' content='text/html; charset=UTF-8'>
<style>
*, *:before, *:after { padding: 0px; border: 0px; margin: 0px; box-sizing: border-box; }
#grid > div { border: 20px solid orange; }
</style>
</head>
<body style='width: 90vw; height: 90vh;'>
  <div id='scrollpane' style='width: 100%; height: 100%; overflow: auto; border: 20px solid yellow;'>
    <div id='grid' style='width: 100%; display: grid; grid-template-columns: 1fr auto 200px 1fr; border: 20px solid lightsteelblue; padding: 20px;'>
      <div>1fr</div><div>auto</div><div>200px</div><div>1fr</div>
    </div>
  </div>
</body>
</html>

最佳答案

在滚动面板上使用display: grid;

*, *:before, *:after {
padding: 0px;
border: 0px;
margin: 0px;
box-sizing: border-box;
}

body {
width: 90vw;
height: 90vh;
}

#scrollpane {
width: 100%;
height: 100%;
overflow: auto;
border: 20px solid yellow;
display: grid; /* solution */
justify-items: stretch; /* or 'start' if you do not want content to track the scrollpane width */
align-items: start; /* or 'stretch' if you want content to track the scrollpane height */
}

#grid {
width: 100%;
display: grid;
grid-template-columns: 1fr auto 200px 1fr;
padding: 20px;
border: 20px solid lightsteelblue;
}

#grid>div {
border: 20px solid orange;
}
<body>
  <div id='scrollpane'>
    <div id='grid'>
      <div>1fr</div>
      <div>auto</div>
      <div>200px</div>
      <div>1fr</div>
    </div>
  </div>
</body>

关于html - CSS 网格滚动问题 : right-side padding and border "overlapping" content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46130586/

相关文章:

android - 索尼安卓电视上支持的 CSS-GRID 浏览器

css - 在 100vh(CSS 网格)中容纳溢出的内容

android - 是 RTL - 支持 android 用于 Web 基础应用程序

html - 链接在 DIV 上但不在内容上

css - Ace 编辑器等宽字体问题与光标间距

javascript - 更改数组中所选元素的颜色

html - 根据网格中元素的数量自动调整 css 中的文本大小

javascript - Canvas window.inner(Width|Height) 滚动条偏移?

python - 如何抓取标签之外的网络数据

css - Odoo 8 qweb报表样式修改