【发布时间】:2023-03-30 17:20:01
【问题描述】:
我想使用带有 https://css-tricks.com/snippets/css/fluid-typography/ 代码的流畅字体大小。但是我的 CSS Meyer Reset (font: inherit;) 似乎覆盖了代码。我不知道为什么?代码如下:
CSS 重置 css:
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font: inherit;
vertical-align: baseline;
}
稍后在 css 样式表中的代码以获得 16px 和 40px 之间的流畅字体大小;
html {
font-size: 16px;
}
@media screen and (min-width: 320px) {
:root {
font-size: calc(16px + (40 - 16) * ((100vw - 320px) / (1000 - 320)));
}
}
@media screen and (min-width: 1000px) {
:root {
font-size: 40px;
}
}
然后,当我在浏览器中以 700px 浏览器大小进行检查时,后一个 css 流体代码被“字体:继承”覆盖。在 CSS 重置代码中。因此,它似乎不适用于流体代码。有任何想法吗?它是否有效?
Picture. Inspection tool in browser shows that the latter code is not active?
流体字体代码有效,但让我感到困惑的是,检查器工具显示它没有被应用,而只显示重置 css font:inherit 被应用。为什么?
【问题讨论】:
-
但它是继承的,因此它将通过继承您定义的值来工作:jsfiddle.net/2m7vtj9x(调整大小并查看)
-
所以你的意思是我的代码确实有效,即使 css 重置字体属性覆盖了流体媒体查询代码?
-
自己测试一下看看。我想你知道它应该如何表现,这样你就可以看到它是否正常工作
-
它似乎有效,但让我感到困惑的是,检查工具取消了媒体查询代码。对我来说,它没有得到应用?见图片。
标签: css fluid typography