我在使用不同高度的右侧栏时遇到了麻烦,例如,将左侧的其他内容向下推,如下所示:



我的主要内容在col-md-9 div中,侧边栏在col-md-3 div中,注释应该在另一个col-md-9 div中的主要内容正下方。现在,如果侧边栏过长,注释会被下推,因此它们从左侧开始,侧边栏在右侧结束。但是,当我缩小屏幕时,流程是正确的:主要内容,侧边栏中的内容和注释,如下所示:



我尝试过添加行,删除行,更改div的顺序以及更改浮动方向。当侧边栏很长时,我该怎么办才能消除多余的空间并使三个div在较小的屏幕上按正确的顺序排列,如下所示:



这是一般的代码:

<div class="col-md-9">
  MAIN CONTENT
</div>
<div class="col-md-3">
  <h2>Sidebar</h2>
  <p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
</div>
<div class="col-md-9">
  <h1>Conversation:</h1>
  <h2>COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS COMMENTS
</div>


这是我一直在玩的a CodePen

最佳答案

您必须重新布置div才能解决该问题。另外,您应该重视侧边栏。

<div class="row">

<div class="col-md-9">

  <div class="row">

    <div class="col-md-12">
      Content
    </div>

    <div class="col-md-12">
     Comment
    </div>

  </div><!--row-->

</div><!--col-md-9-->

<div class="col-md-3">
  Sidebar
</div><!--col-md-3-->

</div><!--main-row-->

关于html - 防止边栏压低内容,将其放在小屏幕的中间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30044908/

10-13 01:59