em与rem

rem是相对单位
em是基于父元素的字体大小
浏览器默认字体是16px,默认行高21px
rem基于根元素,即html标签
例子:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html{
            font-size: 20px;
        }
        body{
            margin: 0;
            padding: 0;
            line-height: 1;
            font-size: 50px;
        }
        .em{
            font-size: 2em;
        }
        .rem{
            font-size: 2rem;
        }
    </style>
</head>
<body>
<div class="em">emmm</div>
<div class="rem">emmm</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_42926749/article/details/82791212