我不明白这种行为。这是一个错误吗?我必须怎么做才能使正确的填充和边框位于(橙色)内容之外?
更新:我想要滚动。问题是右边的填充和边框没有被推到右边,而是与(橙色)内容重叠。
<!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/