CSS - Chrome 和 Firefox 中的 Roboto 字体差异

问题描述

我创建了一个按钮并使用了 Roboto 字体。在各种浏览器(chrome 和 firefox)上进行测试时,我注意到文本似乎有所不同。

问题出现在我使用 font-weight:bold 时。

铬: This is what the font looks like on chrome

火狐: This is what it the font looks like on firefox

这就是 CSS 的样子。

.yellow-button {
  width: 91%;
  height: 48px;
  background: rgba(255,212,1);
  opacity: 1;
  position: absolute;
  top: 109px;
  left: 0;
  right: 0;
  margin-left: auto !important;
  margin-right: auto !important;
  border-radius: 10px;
  Box-shadow: 0px 0px 1px rgba(0,0.03999999910593033);
  overflow: hidden;
}

.button-text {
  width: fit-content;
  color: rgba(55,4,63,1);
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  margin-left: auto !important;
  margin-right: auto !important;
  font-family: Roboto;
  font-weight: Bold;
  font-size: 18px;
  opacity: 1;
  text-align: center;
}
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet" />
<button class="yellow-button">
    <span class="button-text">Hello world test 123</span>
</button>

解决方法

浏览器有一些预定义的 CSS 集,可能会有所不同。为了确保页面在所有浏览器上看起来都一样,最好使用 CSS-reset/CSS-reboot 代码将每个 CSS 设置回零。所有前端框架都使用 CSS-reboot,然后在其上添加自己的 CSS。它看起来有点像这样:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html,body {
    height: 100vh;
    min-height: 100vh;
}

要了解有关 CSS 重置的更多信息,您可以查看此处:CSS-reboot and CSS-resets