在响应式网络上工作时,我可以使用%或大众单元的字体尺寸吗?

发布于 2025-02-13 04:07:23 字数 264 浏览 0 评论 0原文

我必须使用EM或REM单元中的字体尺寸吗?我不能使用%大众单元吗?

语音气泡的宽度为%单位,因此,如果浏览器尺寸减小,字体尺寸固定,则无法匹配语音气泡。因此,我将使用字体大小的大众单元。这是推荐的用法吗?还是如果可能的话,我们应该避免这样做?我应该使用EM或REM单元吗?

我使用了%单位,因此即使是100%,字母也太小。如果我使用大众单元,则字体大小准确出现,但是如果我使用大众单元,如果水平分辨率超过1920及更大,会出现问题吗?车身标签的最大宽度值是我创建的网站上的1920px。

Do I have to use the font size in em or rem units? Can't I use the %vw units?

The width of the speech bubble is % unit, so if the browser size decreases, the font size is fixed, it cannot match the speech bubble. So, I'm going to use vw unit of the font-size. Is this the recommended usage? Or should we avoid doing this if possible? Should I use em or rem units?

I used the % unit, so even if it's 100%, the letters are too small. If I use the vw unit, the font size comes out exactly, but if I use the vw unit, will there be a problem if the horizontal resolution is over 1920 and bigger? The max-width value of the body tag is 1920px on the site I make.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吖咩 2025-02-20 04:07:24

百分比(%)为CSS字体大小:100%等于当前字体大小。这样想:50%是大于0.5倍(较小一半),而150%是字体大小的150%。

<p style="font-size:100%;">Font 100%</p>
<p style="font-size:50%;">Font 50%.</p>
<p style="font-size:150%;">Font 150%.</p>

对于响应字体,您可以使用

<h1 style="font-size:8vw;">Hello World</h1>
<p style="font-size:2vw;">Resize the browser window to see how the font size scales.</p>

Percent (%) as css font size: 100% is equal to the current font size. Think of it this way: 50% is 0.5 times larger ( half smaller ) and 150% is 150 percent of the font size.

<p style="font-size:100%;">Font 100%</p>
<p style="font-size:50%;">Font 50%.</p>
<p style="font-size:150%;">Font 150%.</p>

For a responsive font you can use viewport width/height,

<h1 style="font-size:8vw;">Hello World</h1>
<p style="font-size:2vw;">Resize the browser window to see how the font size scales.</p>

诺曦 2025-02-20 04:07:24

请参阅规范

名称:font-size
值:&lt; absolute-size&gt; | &lt;相对大小&gt; |
&lt;长度度[0,∞]&gt; |数学

  • &lt; absolute-size&gt;

a &lt; absolute-size&gt;关键字是指字体表中的条目
用户代理计算和保留的尺寸。可能的值是:

  [xx-small | X-Small |小|中等大| X-Large | xx-large] 
 
  • &lt;相对大小

a &lt;相对size&gt;关键字是相对于表
字体尺寸和父元素的计算“字体大小”。
可能的值是:

  [较大|较小]
 

例如,如果父元素的字体大小为“介质”,则
“较大”的值将使当前元素的字体大小为
'大的'。如果父元素的大小不靠近表条目
用户代理可以免费插入表格或圆
到最接近的一个。用户代理可能必须推断表
值如果数值超出关键字。

  • &lt; length-gtence&gt;

长度值[CSS-VALUES]指定绝对字体大小
(独立于用户代理的字体表)。负长度为
无效。

百分比值指定相对于的绝对字体大小
父元素的字体大小。使用百分比值或值
EMS会导致更健壮和层叠的样式表。消极的
百分比无效。

相对于视口尺寸的单位不支持。

See the specification:

Name: font-size
Value: <absolute-size> | <relative-size> |
<length-percentage [0,∞]> | math

  • <absolute-size>

An <absolute-size> keyword refers to an entry in a table of font
sizes computed and kept by the user agent. Possible values are:

[ xx-small | x-small | small | medium | large | x-large | xx-large ] 
  • <relative-size>

A <relative-size> keyword is interpreted relative to the table of
font sizes and the computed ‘font-size’ of the parent element.
Possible values are:

[ larger | smaller ]

For example, if the parent element has a font size of ‘medium’, a
value of ‘larger’ will make the font size of the current element be
‘large’. If the parent element's size is not close to a table entry,
the user agent is free to interpolate between table entries or round
off to the closest one. The user agent may have to extrapolate table
values if the numerical value goes beyond the keywords.

  • <length-percentage>

A length value [CSS-VALUES] specifies an absolute font size
(independent of the user agent's font table). Negative lengths are
invalid.

A percentage value specifies an absolute font size relative to the
parent element's font size. Use of percentage values, or values in
ems, leads to more robust and cascadable style sheets. Negative
percentages are invalid.

Units relative to the viewport size are not supported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文