简体   繁体   English

如何使用不同屏幕大小的字体百分比

[英]How to use percentage for font in different screen size

I have the following DIVs: 我有以下DIV:

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

CSS: 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: CSS:

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

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 vw - 相对于视口的宽度
  • vh - relative to viewport's height vh - 相对于视口的高度
  • vmin - relative to viewport's width or height (whichever is the smaller) vmin - 相对于视口的宽度或高度(以较小者为准)
  • vmax - relative to viewport's width or height (whichever is the larger) vmax - 相对于视口的宽度或高度(以较大者为准)

Check out the W3's docs on Viewport Relative Lengths , that states: 查看W3关于视口相对长度的文档 ,其中说明:

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. 当初始包含块的高度或宽度改变时,它们相应地缩放。

You can use media-queries like here: 您可以使用此处的media-queries

@media (max-width: 699px){
  .tckLeftHolder
{
    font-size: 8px; //or how much pixels you want
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM