【发布时间】:2021-07-11 23:54:56
【问题描述】:
我有这个简单的 html 文件,我试图了解为什么当我移动到移动视图时我的字体大小没有按比例缩小。我虽然font-size:7em 会在从桌面移动到移动时进行调整。
我知道这很愚蠢,但我无法理解。我需要使用@media query吗?
`
body {
background: black;
font-family: "Big Caslon";
margin-top:3em;
margin-bottom:3vw;
margin-left:12vw;
margin-right:12vw;
}
section {
color: white;
padding: 1em;
position: absolute;
text-align: center;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.title {
font-size:7em;
margin:10px;
}
<html>
<head>
<title>ShopDoran</title>
<link rel="icon" href="">
<link rel="stylesheet" type="text/css" href="doran.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<section>
<div class="title"> D O R A N </div>
<p style="font-size:2em; margin:10px;">coming soon </p>
</section>
</html>
`
【问题讨论】:
-
您需要查看CSS units 以了解它们的工作原理,并且媒体查询肯定会满足您的预期
-
em是相对于元素的font-size(7em表示当前字体大小的7倍),所以font-size:7em可能是一个递归定义。你的意思是rem?vw和vh也可能会有所帮助。