html - CSS 和 rem : changing the html font-size creates inconsistent dimensions

标签 html css

<分区>

我在我的所有元素中都使用 rems 来计算字体大小和元素尺寸。基本 html 字体大小曾经设置为 10px。当我出于设计原因更改为 11 时,我注意到高度为 .2rem 的重复行显示不一致。这是可以重现该问题的代码笔:https://codepen.io/jalef/pen/djeoxK .如果将 html 字体大小从 10 更改为 11,则会发生同样的事情。

html {
  font-size: 11px;
}

.line {
  height: .2rem;
  width: 50rem;
  background-color: purple;
  margin: 1rem;
}

当 html font-size 设置为 10px 时产生的一致的 .2rem 高度线: html font-size equal to 10px : consistent .2rem height line

当 html font-size 设置为 11px 时产生的不一致的 .2rem 高度线: html font-size equal to 11px : inconsistent .2rem height line

发生这种情况是否有原因,是否有解决方法?

谢谢!

最佳答案

可能是浏览器渲染问题。

你可以尝试用边框代替div的高度。

例子:

border-bottom: 0.2rem solid purple;

enter image description here

关于html - CSS 和 rem : changing the html font-size creates inconsistent dimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51649784/

上一篇:css - Flexbox 2 列但间隔为 3

下一篇:jQuery 如果屏幕很小时条件不起作用(移动)

相关文章:

html - 使用 CSS 或 SVG 创建 Tab 形状

html - CSS伪类回退?

css - 使用嵌套在具有 css 动画的元素中的 css 转换时出现问题

css - FontAwesome - 图标显示为一个盒子 - 使用没有 rails 的 compass

javascript - jQuery 克隆和递增输入、文本区域,具有名称、id 和 for

javascript - React JS 将组件添加到特定的点击行

html - 在特定窗口宽度处向左浮动中断

css - 确保 div 永远不会相互交叉

html - 根据另一个 div 的高度设置一个 div 的最小高度

javascript - 我如何获取jsp内Javascript函数的值?