如何在不同屏幕尺寸下使用百分比字体(How to use percentage for font in different screen size)

编程入门 行业动态 更新时间:2024-10-11 21:28:46
如何在不同屏幕尺寸下使用百分比字体(How to use percentage for font in different screen size)

我有以下DIV:

<div class="tckLeftHolder"> <div class="tckLeftContents"> <span>URGENT CARE WAIT</span> </div> </div>

CSS:

.tckLeftContents { text-align: center; width: 90%; padding: 0 0 0 10%; height: 35px; overflow: hidden; } .tckLeftHolder { float: left; width: 25%; height: 35px; line-height: 17px; vertical-align: middle; background: #EA7C30; border-top-left-radius: 10px; border-bottom-left-radius: 10px; color: #FFFFFF; font-family: Verdana; font-size: 10px; overflow: hidden; text-align: center; box-shadow: inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(238,146,85,1); }

以不同的屏幕尺寸显示它:

如何使字体响应,以便根据屏幕大小增加/减少。

更新:

CSS:

@media (min-width: 500px) and (max-width: 860px) { .tckLeftContents { font-size: 1vmin; } }

I have the following DIVs:

<div class="tckLeftHolder"> <div class="tckLeftContents"> <span>URGENT CARE WAIT</span> </div> </div>

CSS:

.tckLeftContents { text-align: center; width: 90%; padding: 0 0 0 10%; height: 35px; overflow: hidden; } .tckLeftHolder { float: left; width: 25%; height: 35px; line-height: 17px; vertical-align: middle; background: #EA7C30; border-top-left-radius: 10px; border-bottom-left-radius: 10px; color: #FFFFFF; font-family: Verdana; font-size: 10px; overflow: hidden; text-align: center; box-shadow: inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(238,146,85,1); }

Displays this in different screen size:

How can I make the font be responsive, so that the size increases/decreases based on the screen.

Update:

CSS:

@media (min-width: 500px) and (max-width: 860px) { .tckLeftContents { font-size: 1vmin; } }

最满意答案

您可以使用视口单位,该视口单位根据定义的容器大小(宽度和/或高度)

{ font-size: 1vmin; }

作为可能的价值观:

vw - 相对于视口的宽度 vh - 相对于视口的高度 vmin - 相对于视口的宽度或高度(以较小者为准) vmax - 相对于视口的宽度或高度(以较大者为准)

查看关于视口相对长度W3文档 ,其中指出:

视口百分比长度相对于初始包含块的大小。 当初始包含块的高度或宽度发生变化时,会相应地缩放。

You can use viewport units, that vary based on the defined container's size (width and/or height)

{ font-size: 1vmin; }

Being the possible values:

vw - relative to viewport's width vh - relative to viewport's height vmin - relative to viewport's width or height (whichever is the smaller) vmax - relative to viewport's width or height (whichever is the larger)

Check out the W3's docs on Viewport Relative Lengths, that states:

The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they are scaled accordingly.

更多推荐

本文发布于:2023-08-06 10:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1447659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:百分比   字体   如何在   屏幕尺寸   size

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!