html - 在不同屏幕尺寸上调整文本大小的最佳做法

标签 html css

我正在尝试找出在不同大小的设备上调整 div 内文本大小的最佳方法。在这个演示中,我多次使用了媒体查询,但这并不是最有效的方法。

有没有人有比这更好的做法?显然,我的解决方案仅适用于此演示中的确切文本量,这对于大小相同但文本量不同的其他 div 来说不是很好。

我很想听听您的想法。

.first-news-article-description {
    background: orange;
    width: 100%;
    height: 100px;
    padding: 15px;
}
@media(max-width:768px) {
  .first-news-article-description {background:yellow}
  h2 {font-size: 1.2em}
}
@media(max-width:600px) {
  .first-news-article-description {background:red}
  h2 {font-size: 1.0em}
}
@media(max-width:450px) {
  .first-news-article-description {background:blue}
  h2 {font-size: 0.8em}
}
@media(max-width:350px) {
  .first-news-article-description {background:red}
  h2 {font-size: 0.7em}
}
<div class="first-news-article-description">
            <h2>Some random text that needs to resize properly on different devices</h2>
            <span>Some more text</span>
        </div>

最佳答案

有一个单位叫做viewport width。您可以使用它来调整文本大小而无需使用媒体查询。找到下面的例子

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

关于html - 在不同屏幕尺寸上调整文本大小的最佳做法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50445015/

相关文章:

html - Jekyll site.baseurl 在永久链接中丢失

html - 手机网站白线

html - 使用非正统的 `head {display: block}` 向用户显示文本?

jquery - 使用 jQuery.css 在 Internet Explorer 中获取值

html - 使用 XPath 查找动态表值

html - 当我在其内容的第一个数字处有一个数字时,跨越边界半径问题(在 chrome 中)

html - 如何将div放置在彼此之上并水平对齐

javascript - 如何在 ionic 中制作下拉框或选择框

CSS3 Transform 向左平移

html - 我可以在 ngStyle 中使用 lighten css 属性吗?