显示Flex以适应移动页面或自适应页面

时间:2020-08-21 17:10:27

标签: html css

我希望以下内容在PC上的宽度相等,在移动设备上的宽度为100%。

    <style>
        .container {
          display: flex;
          flex-wrap: wrap;
        }
    
        .box-left {
width: 100%
        }
    
        .box-right {
width: 100%
        }
    </style>
    
          <div class="container">
          <div class="box-left">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
            veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
            commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
            velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
            occaecat cupidatat non proident, sunt in culpa qui officia deserunt
            mollit anim id est laborum.
          </div>
          <img class="box-right" src="https://i.imgur.com/gawfygm.png" />
        </div>

1 个答案:

答案 0 :(得分:0)

展开或缩小视图以检查其是否正常工作。

.container {
  display: flex;
  flex-direction: column;
}

.box-left {
  width: 100%;
  font-size: 1rem;
  font-family: 'Work Sans', sans-serif;
  line-height: 1.5;
  padding: 1rem;
}

.box-right {
  margin: 0 auto;
  width: 100%;
  height: auto;
}

@media(min-width:576px) {
  .container {
    flex-direction: row;
  }
  .box-left {
    width: 50%;
    background: lightblue;
  }
  .box-right {
    width: 50%;
    background: lightcoral;
  }
}
<div class="container">
  <div class="box-left">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </div>
  <img class="box-right" src="https://i.imgur.com/gawfygm.png" />
</div>