html - :after 元素意外高度行为
问题描述
有人可以解释为什么 :after 元素高度取决于顶级属性值吗?
.bar {
width: 30px;
height: 2px;
background-color: white;
position: absolute;
justify-content: center;
top: 0; bottom: 0; left: 0; right: 0;
margin: auto;
}
/* Height of bar match to main element 2px */
.bar:before {
content: '';
width: 30px;
height: 2px;
top: -11px; /* It works */
background-color: inherit;
position: absolute;
}
/* Height of bar doesn't match to main element 2px */
.bar:after {
content: '';
width: 30px;
height: 2px;
top: 10px; /* It doesn't work */
background-color: inherit;
position: absolute;
}
解决方案
我大概知道为什么会这样了。在 Windows 显示设置比例较小的全高清显示器上,默认设置为 125%。因此浏览器窗口的宽度也被缩放。
推荐阅读
- symfony - Twig 翻译连接
- mysql - 包含 200.000 多条记录的表需要 4 秒选择
- php - php-win.exe - 应用程序无法正确启动
- javascript - if-else 不能在 javascript (jquery) 中工作
- python - 带有部分洗牌的 TensorFlow 数据集
- java - Selenium:我可以断言点击尚未完成吗?
- python - 如何计算神经网络模型的准确性
- css - 是否可以在 Angular Material Design 中为按钮样式设置主题
- javascript - 在其他反应组件中设置状态
- javascript - 未捕获的格式错误的表格行,未定义单元格。无法在数据表中生成 pdf