两栏布局之将右边的dom放在前面

2020-10-17  本文已影响0人  六寸光阴丶
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta
    name="viewport"
    content="width=device-width, initial-scale=1.0"
  >
  <title>Document</title>
  <style>
    .margin-bottom {
      margin-bottom: 10px;
    }

    .container1 {
      position: relative;
    }

    .left1 {
      background-color: green;
      height: 200px;
      width: 200px;
      position: absolute;
      left: 0;
      top: 0;
    }

    .right1 {
      background-color: yellow;
      height: 200px;
      margin-left: 200px;
    }

    .container2 {
      display: flex;
      flex-direction: row-reverse;
    }

    .left2 {
      background-color: green;
      height: 200px;
      width: 200px;
    }

    .right2 {
      background-color: yellow;
      height: 200px;
      flex: 1;
    }

    .container3 {
      padding-left: 200px;
    }

    .left3 {
      background-color: green;
      height: 200px;
      width: 200px;
      float: left;
      margin-left: -100%;
      position: relative;
      left: -200px;
    }

    .right3 {
      background-color: yellow;
      height: 200px;
      width: 100%;
      float: left;
    }
  </style>
</head>

<body>
  <div class="container1 margin-bottom">
    <div class="right1">right</div>
    <div class="left1">left</div>
  </div>
  <div class="container2 margin-bottom">
    <div class="right2">right</div>
    <div class="left2">left</div>
  </div>
  <div class="container3">
    <div class="right3">right</div>
    <div class="left3">left</div>
  </div>
</body>

</html>
image.png
上一篇下一篇

猜你喜欢

热点阅读