Html 将盒子两个一个地对齐

Html 将盒子两个一个地对齐,html,css,Html,Css,我有三排三排的盒子,在更宽的屏幕(PC)上。我想让它们在较小的屏幕(手机)上每行对齐两个,以占据整个屏幕的宽度(包括边距、填充…)。我怎样才能做到这一点?另外,其中一些比其他的高40像素。现在我有一个更宽屏幕的CSS: .parents-parent { margin: auto; width: 700px; } .parent { float: left; width: 200px; background-color: white; border

我有三排三排的盒子,在更宽的屏幕(PC)上。我想让它们在较小的屏幕(手机)上每行对齐两个,以占据整个屏幕的宽度(包括边距、填充…)。我怎样才能做到这一点?另外,其中一些比其他的高40像素。现在我有一个更宽屏幕的CSS:

.parents-parent {
    margin: auto;
    width: 700px;
}
.parent {
    float: left;
    width: 200px;
    background-color: white;
    border: 1px solid rgb(230,230,230);
    margin: 10px;
  }
  .parent:nth-child(3n + 1) {
   clear: left; 
 }
和HTML:

<div class="parents-parent">
{% for exam in exams %}

  <div class="parent" exam-id="{{ exam.pk }}" csrf="{{ csrf_token }}">

    <div class="exam-title">
      <a><b>Test številka {{ exam.exam_number }}</b></a>
    </div>

  <a class="exam-span-wrapper">
    <div class="exam-box-el  exam-span-file">
      <span class="glyphicon glyphicon-file"></span> Test
    </div>

    <ul class="exam-ul">
      {% for file in exam.examfile_set.all %}
      <li class="exam-li-img" src="{{ file.exam_file.url }}" alt="Slika Testa" width="60" height="60" class="img-resposive exam-img">Slika Testa {{ forloop.counter }}</li>
      {% endfor %}
    </ul>

  </a>

  <a class="comment">
    <div class="exam-box-el"> 
      <span class="glyphicon glyphicon-comment"></span> Komentarji
    </div>
  </a>

  <a class="mark-exam">
    <div class="exam-box-el">
      <span class="glyphicon glyphicon-ban-circle {% if user in exam.exam_mark.all %}active{% endif %}"></span> Potrebno popravka
    </div>
  </a>

  <a href="{% url 'profile' exam.exam_user %}">
    <div class="exam-box-el">
      <span class="glyphicon glyphicon-user"></span> {{ exam.exam_user }}
    </div>
  </a> 

  {% if exam.exam_user == user %}
  <a href="#" class="remove-exam">
    <div class="exam-box-el more">
      <span class="glyphicon glyphicon-remove glyphicon-remove-exam"></span>
        Odstrani
    </div>
  </a>
  {% endif %}

</div>


{% endfor %}

</div>

{%用于考试中的考试%}
{%if-exam.exam_user==user%}
{%endif%}
{%endfor%}

您可以使用
@media
查询当前布局开始中断的位置,并指定占行50%的宽度,然后清除每个
:第n个子元素(奇数)
元素

.parent{
浮动:左;
宽度:200px;
背景色:白色;
边框:1px实心rgb(230230230);
利润率:10px;
}
.父项:第n个子项(3n+1){
清除:左;
}
@介质(最大宽度:682px){
.父项:第n个子项(3n+1){
明确:无;
}
.父母:第n个子女(单数){
清除:左;
}
.家长{
宽度:计算(50%-22px);
}
}
foo
福
福
福
福
福
福
福

foo
这非常有效!有什么办法可以居中吗?父母作为保证金:汽车似乎不起作用?此外,我没有包括父计算宽度,因为它会拉伸box@skin伟大的指定的
宽度
边距:自动
将使块元素水平居中。如果这不起作用,则需要包含再现问题的相关代码。你现在所拥有的将成为中心。父母。但是,请避免在发表原始帖子后更改您的问题或提出新问题-这听起来像是一个新问题,因此如果您需要帮助,请发表新帖子。