有没有一种方法可以将文本大小作为浏览器窗口的百分比来设置样式?例如:
h1
{
height: 15%;
/* in my ideal world this would be 15% of the window
(or parent) size rather than inherited font-size */
}
CSS3中:
h1{
font-size: 15vw; // relative to the viewport's width
font-size: 15vh; // relative to the viewport's height
font-size: 15vm; // relative to the ratio width/height of the viewport
}
这不会完美,但使用媒体查询可以接近。
@media screen and (max-height: 50px) {
body {
font-size: 7.5px;
}
}
@media screen and (max-height: 100px) {
body {
font-size: 15px;
}
}
@media screen and (max-height: 150px) {
body {
font-size: 22.5px;
}
}
@media screen and (max-height: 200px) {
body {
font-size: 30px;
}
}
等等。您需要确定何时设置“断点”,以及在低端和高端上应该采取多远。