这个用代码怎么打出来,我学到定位了

img

能不用定位就尽量不用定位,这个用弹性盒子就可以做出来

<!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>
    *{margin: 0;padding: 0;}
    .coon{display: flex;align-items: center;justify-content: center;}
    .box{height: 100vh;}
    .a{width: 80%;height: 50%;background: green;}
    .b{width: 90%;height: 30%;display: flex;justify-content: space-between;}
    .b>div{width: 200px;height: 100%;background: red;}
  </style>
</head>
<body>
  <div class="box coon">
    <div class="a coon">
      <div class="b">
        <div></div>
        <div></div>
      </div>
    </div>
  </div>
</body>
</html>

用定位写的如有帮助请点采纳

img

<!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>定位解决</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        /* 父相子绝 */
        .box{
            width: 500px;
            height: 300px;
            margin: 20px auto;
            background-color: chocolate;
            /* 父亲相对定位 */
            position: relative;
        }
        .a,.b{
            width: 50px;
            height: 50px;
            background-color: red;
        }
        .a{
            /* 儿子绝对定位 */
            position: absolute;
            top: 125px;
            left: 40px;
        }
        .b{
            /* 儿子绝对定位 */
            position: absolute;
            top: 125px;
            right: 40px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="a"></div>
        <div class="b"></div>
    </div>
    </div>
</body>

</html>