css - Can someone explain the difference between these css lines?
问题描述
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
margin: 0;
}`
I tried removing each of these separately, and saw no difference.
解决方案
html {
box-sizing: border-box;
}
设置box-sizing
为border-box
您的根元素
*,
*::before,
*::after {
box-sizing: inherit;
}
这里所有子元素,包括伪元素,都设置为继承box-sizing
值(从根元素)
在这里阅读box-sizing
:
https ://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
body {
margin: 0;
}
大多数(或所有?)浏览器在正文元素上都有默认边距。如果您的代码是
<body>
Some text
</body>
浏览器边缘会有一点空间。为了“规范化”它并从浏览器的边缘开始您的设计,margin 设置为0
.
推荐阅读
- autohotkey - ControlSend 不发送到非最顶层窗口
- jenkins - 如何为 groovy.io.FileType 文件批准 Jenkins 脚本化管道 RejectedAccessException?
- python-3.x - 我收到以下导入错误,尽管我安装了 numpy
- python - 如何使用“scipy.optimize.curve_fit”平滑拟合我的数据点?
- android - 如何修复 vmlinux.o 错误和交叉编译错误
- vue.js - vue:你可能需要一个合适的加载器来处理这个文件类型
- java - 如何正确编写扩展功能而不是导入语句?
- batch-file - 批量将文件移动到不包括父目录的子目录中
- java - 如何将字符串添加到 TextView / ScrollView?
- scikit-learn - ScikitLearn 的 MLPClasssifier 在输出层使用什么样的激活?