0
点赞
收藏
分享

微信扫一扫

响应式布局的实现方式(5种)

北冥有一鲲 2022-04-14 阅读 71
html

1、百分比布局 

<!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> %和rem 布局</title>
    <style>
      html {
        font-size: 30px;
      }
      .box2 {
        width: 10rem;
        height: 10rem;
        background-color: plum;
      }
      .box {
        width: 80%;
        height: 200px;
        background-color: aquamarine;
      }
      .part {
        width: 80%;
        height: 80%;
        background-color: pink;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="part"></div>
    </div>
    <div class="box2"></div>
  </body>
</html>

2、rem布局 

<!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>rem布局</title>
    <style>
      html {
        font-size: 20px;
      }
      .r1 {
        width: 2rem;
        height: 2rem;
        background-color: plum;
      }
      .r2 {
        width: 40px;
        height: 40px;
        background-color: aquamarine;
      }
    </style>
  </head>
  <body>
    <div class="r1"></div>
    <div class="r2"></div>
  </body>
</html>

 

 

3 媒体查询 @media screen               

<!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>@media screen</title>
    <style>
      .box {
        width: 10rem;
        height: 10rem;
        background-color: pink;
        margin-left: 20rem;
      }
      @media screen and (min-width: 1200px) {
        html {
          font-size: 20px;
        }
      }
      @media screen and (max-width: 1200px) {
        html {
          font-size: 10px;
        }
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
  </body>
</html>

4 flex布局  

5、vw 和 vh

 

(1条消息) 前端响应式布局原理与方案(详细版)_weixin_34273479的博客-CSDN博客icon-default.png?t=M276https://blog.csdn.net/weixin_34273479/article/details/91401352?spm=1001.2101.3001.6650.1&depth_1-utm_relevant_index=2

举报

相关推荐

0 条评论