简体   繁体   English

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

[英]Best practices for resizing text on different screen sizes

I'm trying to figure out the best way of resizing text inside a div on different sized devices. 我正在尝试找出在不同大小的设备上的div中调整文本大小的最佳方法。 In this demo, I've used the media query many times, but this doesn't feel like the most efficient way of doing it. 在此演示中,我已经多次使用媒体查询,但这并不是最有效的方法。

Does anyone have any better practices than this? 有没有人比这更好的做法? Obviously my solution only accommodates for the exact amount of text in this demo, which wouldn't be great for other divs of the same size but with different amounts of text in. 显然,在此演示中,我的解决方案仅适应确切数量的文本,这对于相同大小但包含不同文本量的其他div来说不是很好。

I'm interested in hearing your thoughts. 我有兴趣听听您的想法。

 .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> 

There is a unit called viewport width . 有一个称为viewport width的单位。 You can use it to resize the text-size without using media query. 您可以使用它来调整文本大小,而无需使用媒体查询。 Find the example below 在下面找到示例

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

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

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