<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html {
font-size: 20px;
}
body {
font-size: 12px
}
span {
font-size: 2rem;
font-size: 1em;
}
</style>
</head>
<body>
<span>
em是根据父元素的font-size大小来计算<br>
rem是根据html元素的font-size大小来计算<br>
需要注意的是em和rem不仅可以应用于字体还可以用来应用宽
%和em差不多 不过是把1变成100%
</span>
</body>
</html>
评论