移动版中的响应块

时间:2019-02-24 19:40:06

标签: html css responsive

我在一列中有6个区块。我需要在移动版本中连续看到2个区块,如图片enter image description here

因此,我将有3行,每行2块。那么,我该怎么做呢?你能帮助我吗?我是网络新手。

CSS:

* {
  box-sizing: border-box;
}

img {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 100%;
}

.picture-box {
  width: 70%; /* limit screen width - max width could have been used aswell */
  margin: 0 auto; /* center content */
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.ring {
  padding: 10px;
  text-align: center; /* Center ring div */
}

@media screen and (min-width: 1200px) {
   .ring {
      width: 25%;
    }
}

@media screen and (max-width: 1199px) {
   .ring {
      width: 33.33%;
    }
}

@media screen and (max-width: 768px) {
    .ring {
      width: 50%;
    }

    .picture-box {
      width: 100%;
    }
    .picture-box {
    flex-direction:column;
    }
}

.thumb {
  display: inline-block;
  max-width: 200px;
  padding: 10px;
  border: 1px solid blue;
}

HTML:

<div class="picture-box">
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
</div>

在此示例中,它不能按我的要求工作,您能帮我解决问题吗?

1 个答案:

答案 0 :(得分:0)

请检查它是否是您想要的解决方案。

.picture-box{
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}

.ring{
  margin-right: 10px;
  
}

.ring:last-child{
  margin-right: 0;
}

@media screen and (max-width: 768px){
  
  .picture-box{
      width: 100%;
      flex-wrap: wrap;
    }
  
  .ring{
    width: calc(50% - 10px);
    flex: 1 1 calc(50% - 10px);
  }  
  
  .ring:nth-child(even){
    margin-right: 0;
  }
}
<div class="picture-box">
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
  <div class="ring">
    <div class="thumb">
      <img src="https://via.placeholder.com/200">
    </div>
  </div>
</div>