Fixed left, right adaptive solutions

1 Firstly float

Left to set the width, height, left to float

Do not write the right width to height, to set the left margin-left width of the container, softened

Div block elements as belonging to automatically fill line

<!DOCTYPE html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .left {
      width: 200px;
      height: 100px;
      background: blueviolet;
    }

    .right {
      background: goldenrod;
      height: 100px;
    }

    .l {
      float: left;
    }

    .r {}
  </style>
</head>

<body>
  <div>
    <div class="left l">固定200px</div>
    <div class="right r">自动充满</div>
  </div>
</body>
<script>

</script>

</html>

 

 

2 by the positioning

Parent disposed relative positioning

Set about absolute positioning, the right to set the width of one hundred percent open strange box, padding-left is set to the width of the left,

Key left z-index is set to 1, the right upper float

<!DOCTYPE html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .left {
      width: 200px;
      height: 100px;
      background: blueviolet;
    }

    .right {
      background: goldenrod;
      height: 100px;
    }

    .l {
      position: absolute;
      z-index: 1;
    }

    .r {
      position: absolute;
      right: 0;
      top: 0;
      width: 100%;
      padding-left: 200px;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
  <div style="position: relative;">
    <div class="left l">固定200px</div>
    <div class="right r">自动充满</div>
  </div>
</body>
<script>

</script>

</html>

 

 

3 by the elastic box

<!DOCTYPE html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .left {
      width: 200px;
      height: 100px;
      background: blueviolet;
    }

    .right {
      background: goldenrod;
      height: 100px;
    }

    .l {}

    .r {
      flex: 1;
    }
  </style>
</head>

<body>
  <div style="display: flex;">
    <div class="left l">固定200px</div>
    <div class="right r">自动充满</div>
  </div>
</body>
<script>

</script>

</html>

 

Guess you like

Origin www.cnblogs.com/skydragonli/p/11669142.html