<!DOCTYPE html><html lang="en" style="font-size: 50px"><head> <meta charset="UTF-8"> <title>Document</title> <style> body { margin: 0; padding: 0; line-height: 1; } .container { font-size: 25px; } .em { font-size: 2em; } .rem { font-size: 2rem; } </style></head><body> <div class="container"> <div class="em">AAAAA</div> <div class="rem">AAAAA</div> </div></body></html>
<!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, user-scalable=no"> <title>rem适配</title> <style type="text/css"> * { margin: 0; padding: 0; } /* 假设的设备 320 414 640 */ @media (min-width: 320px) { html { font-size: 50px; } } @media (min-width: 414px) { html { font-size: 64.6875px; /* 100/640*414 */ } } @media (min-width: 640px) { html { font-size: 100px; } } /* rem适配 */ header { width: 100%; height: 1rem; line-height: 1rem; font-size: 0.32rem; text-align: center; background: green; color: #fff; } </style></head><body> <header>购物车</header></body></html>