如何将文本调整为浏览器大小?

时间:2014-01-02 19:19:34

标签: html css text

我怎样才能这样做,当我使浏览器窗口变小时,文本会调整?目前,当我把文件缩小时,文字太大了。

1 个答案:

答案 0 :(得分:1)

使用媒体查询。

/* styles for desktop viewing could go here */ 
@media screen and (min-width:1025px) {
    body {
        font-size:24px;
    }
}

/* styles for a tablet could go here */  
@media screen and (min-width:768px) and (max-width:1024px) {
    body {
        font-size:16px;
    }
}
/* styles for mobile devices in landscape mode could go here */
@media screen and (max-width:767px) and (orientation:landscape) {
    body {
        font-size:12px;
    }
}

因此,您可以在任意数量的媒体查询中为任意大小的窗口放置所需的样式。只需相应调整最大宽度和最小宽度值即可。此外,最好查看媒体查询的官方文档,以便了解所有可用选项。

http://www.w3.org/TR/css3-mediaqueries/

关于浏览器兼容性,您应该使用检查来判断浏览器是否支持媒体查询。很多人都有IE的问题,特别是旧版本。以下是Internet Explorer 8检查的示例。

<!--[if IE 8]>
...
<![endif]-->