【问题标题】:CSS - Roboto Font discrepancy in Chrome and FirefoxCSS - Chrome 和 Firefox 中的 Roboto 字体差异
【发布时间】:2021-03-08 07:09:37
【问题描述】:

我创建了一个按钮并使用了 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, 0, 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, 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 cross-browser webfonts roboto


    【解决方案1】:

    浏览器有一些预定义的 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

    【讨论】:

    • 使用'normalize'还是'reset'更好?
    • 两者都有自己的用途。在我看来,您应该使用适合您项目需求的那个。 @RickHellewell
    猜你喜欢
    • 2016-06-14
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 2017-01-17
    • 2015-02-09
    • 1970-01-01
    相关资源
    最近更新 更多