【发布时间】:2021-07-13 21:29:18
【问题描述】:
我使用media query 在窗口缩小时缩放字体大小。我用rem 为我的容器分配宽度和高度值。
当我打开开发工具并调整窗口大小时,一切都按预期工作。但是在我的手机上,这个设计坏了。
使用 Safari 和 chrome 在 Iphone 7 plus 和 Iphone xr 上测试。
这是一个例子:
html {
font-size: 62.5%;
}
body {
height: 100vh;
}
.grid {
display: block;
width: 100%;
height: 100%;
display: grid;
grid-template-columns: repeat(2, 30rem);
gap: 4rem 10rem;
grid-auto-rows: 30rem;
justify-content: center;
align-content: center;
}
.box {
width: 30rem;
height: 30rem;
background-color: green;
}
@media screen and (max-width: 1800px) {
html {
font-size: 60%;
}
}
@media screen and (max-width: 825px) {
html {
font-size: 40%;
}
}
@media screen and (max-width: 540px) {
html {
font-size: 30%;
}
}
@media screen and (max-width: 400px) {
html {
font-size: 25%;
}
}
@media screen and (max-width: 300px) {
html {
font-size: 15%;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="styles.css?v=17" />
<title>test</title>
</head>
<body>
<div class="grid">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</body>
</html>
【问题讨论】:
标签: html css responsive-design