css - 为什么我的 CSS Grid 容器偏离了 1 个像素?
问题描述
当我在 Chrome DevTools 中检查我的布局网格容器时,我的网格似乎被向右推了 1 个像素。我能够看到网格的左侧边框,但右侧边框不在屏幕上。
这个问题的原因可能是什么?
我有以下全局CSS:
html, body {
height: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
}
以及我的网格容器的以下 CSS:
.container {
background-color: #F5F6F9;
position: relative;
min-height: 100vh;
display: grid;
grid-template-columns: 100px minmax(1080px, 1fr) 100px;
grid-template-rows: 75px minmax(150px, 1fr) 75px;
grid-template-areas:
"header header header"
". main ."
"footer footer footer";
}
我想也许添加box-sizing: border-box
到全局 css 可以解决这个问题,但没有任何改变。
解决方案
I dont know if this is the solution you are looking for, but HTML body have a safe space of 8px as its margin. So when you set the margin: 0px; , you also remove the safe space along with it. However, you can always set the margin-right to 1px so you can see the border.
Forced method, change your body margin:
html, body {
height: 100%;
padding: 0;
margin: 0px 1px 0px 0px;
box-sizing: border-box;
}
推荐阅读
- javascript - 我的按钮影响具有不同 id 的两个跨度
- python - 双向广度优先搜索错误
- php - 在mysql类型时间中插入输入时间内容
- php - 在 Larvael 中使用队列发送邮件
- javascript - 在 Bootstrap 4 中折叠卡片表行时更改字体真棒图标
- go - Plan 9 中的“临时”文件模式是什么,它在 Linux 中可用吗?
- http - 必应 API HTTP 请求超时
- reactjs - 反应“未捕获的类型错误:无法读取未定义的属性”
- vba - 将 Application.worksheetfunction 作为公式插入到单元格中
- machine-learning - 神经网络训练 - 多输出 CNN