Bootstrap 4 中列之间的空白垂直空间 [英] Empty vertical space between columns in Bootstrap 4

查看:20
本文介绍了Bootstrap 4 中列之间的空白垂直空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 html 结构:

<div class="row"><div class="col-lg-9 描述"></div><div class="col-lg-3 sidebar"></div><div class="col-lg-9 评论"></div>

最终效果是这样的:我需要这个 HTML 结构,因为当我有一个较小的视口并且 Bootstrap 切换到 1 列模式时,我需要侧边栏列在描述和评论列之间(实际上有空白区域).

问题是我想避免在模板未处于移动模式"时出现空白空间.

我尝试了很多方法,但我无法做到这一点,有人可以帮助我吗?

编辑

我试过这种方式:

<div class="row"><div class="col-lg-9"><div class="description"></div><div class="comments"></div>

<div class="col-lg-3 sidebar"></div>

并尝试使用cssorder"重新排序,但没有用(它允许我做的唯一一件事就是将侧边栏放在页面的开头,但这不是我想要的).

解决方案

发生这种情况是因为 Bootstrap 4 是 flexbox,并且所有的列都变成与最高的列相同的高度...>

取而代之的是:

 ---------- ---------||||||||------------------ ||------------------ ||||||------------------ ---------

你明白了:

 ---------- ---------||||||||------------------ ||||||------------------ ---------||------------------


通常,您可以通过嵌套列来解决此问题(正如您尝试过的那样),但是您将无法获得所需的列顺序....

嵌套:

<div class="row"><div class="col-lg-9"><div class="row"><div class="col-lg-12 description"></div><div class="col-lg-12 评论"></div>

<div class="col-lg-3 sidebar"></div>

但是,要获得所需的列顺序,列必须包含在单个 .row 中.

浮动:

因此,BS4 中的解决方法是使用浮点数(如 BS3 所做的那样),如下所述:引导程序 4 - 我不想要列具有相同的高度.像这样:

https://www.codeply.com/go/wnRnLl3Jmo

<div class="row d-lg-block"><div class="col-lg-9 float-left description">Desc

d-lg-block 在行上设置 display:block 而不是 display:flex 允许列在 lg 屏幕宽度.

相关:
移动版本上不同顺序的引导程序

I have this html structure:

<div class="container">
   <div class="row">
      <div class="col-lg-9 description"></div>
      <div class="col-lg-3 sidebar"></div>
      <div class="col-lg-9 comments"></div>
   </div>
</div>

The final effect is this: I need this HTML structure because when I have a smaller viewports and Bootstrap switches to the 1-column mode, I need that sidebar column goes between description and comments columns (where actually there is the empty space).

The problem is that I want to avoid to have that empty space when the template isn't in "mobile mode".

I tried many ways but I can't achieve this, someone could help me?

EDIT

I tried this way:

<div class="container">
   <div class="row">
      <div class="col-lg-9">
         <div class="description"></div>
         <div class="comments"></div>
      </div>
      <div class="col-lg-3 sidebar"></div>
   </div>
</div>

And tried to reorder by using the css "order", but doesn't worked (the only thing it allows me to do is to put sidebar at the start of the page, but isn't what I want).

解决方案

It's happening because Bootstrap 4 is flexbox, and all of the columns become the same height as the tallest column...

Instead of this:

 ------------------  ---------
|                  ||         |
|                  ||         |
 ------------------ |         |
 ------------------ |         |
|                  ||         |
 ------------------  ---------

You get this:

 ------------------  ---------
|                  ||         |
|                  ||         |
 ------------------ |         |
                    |         |
                    |         |
 ------------------  ---------
|                  |
 ------------------


Usually, you can workaround this (as you tried) by nesting the columns, but then you won't get the desired column order....

Nesting:

<div class="container">
    <div class="row">
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12 description"></div>
                <div class="col-lg-12 commments"></div>
            </div>
        </div>
        <div class="col-lg-3 sidebar"></div>
    </div>
</div>

However, to get the desired column order, the columns must be contained in a single .row.

Floats:

So, the workaround in BS4 is to use floats (like BS3 did) as explained here: Bootstrap 4 - I don't want columns to have the same height. Like this:

https://www.codeply.com/go/wnRnLl3Jmo

<div class="container">
   <div class="row d-lg-block">
      <div class="col-lg-9 float-left description">Desc</div>
      <div class="col-lg-3 float-right sidebar">Sidebar</div>
      <div class="col-lg-9 float-left comments">Comments</div>
   </div>
</div>

The d-lg-block sets display:block on the row instead of display:flex which allows the columns to float in lg screen widths.

Related:
Bootstrap with different order on mobile version

这篇关于Bootstrap 4 中列之间的空白垂直空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆