【问题标题】:Unequal column height with bootstrap4 Flexbootstrap4 Flex 的柱高不等
【发布时间】:2018-10-23 14:37:30
【问题描述】:

我正在使用 Boostrap4 并尝试制作一个简单的 4*4 div 网格,其中包含图像和一些文本。最初,我尝试使用嵌套在一行中的 6 列,结果看起来像:

所以这里的问题是图片不在列的中心。所以接下来我在行上使用了text-center。这行得通,但现在当我希望文本与图像左侧对齐时,文本也居中:

所以我最终放弃了所有这些,摆脱了引导行和列,并尝试使用引导的 flex 类。这具有一般结构:

<div class="d-flex justify-content-around">
    <div class="d-flex flex-column">
        <div> image and text content here </div>
    </div>
</div>

现在这很好用,只是因为列高可以变化,所以行看起来不对齐:

有什么方法可以解决这个问题?尝试使用 bootstrap4 制作这样的 div 网格时,最佳做法是什么?

因为有人想查看整个代码。

<div class="row border justify-content-around border-r flex-wrap">
                    <div class="d-flex flex-column border-r"> <!-- this is repeated twice more for each column -->
                        <div class="tile">
                            <a href="./wanderlust.html">
                                <img class ="thumbnail img-fluid" src ="images/wanderlust.jpg"/>
                                <h5 class=" thumbnail-title"> Wanderlust </h5>
                                <p class=" thumbnail-subtitle"> design research + UX + UI <br> +  programming </p>
                            </a>
                        </div>
                        <div class="tile">
                            <a href ="behavior-change.html">
                                <img class ="thumbnail img-fluid" src ="images/breakfast.jpg">
                                <h5 class="thumbnail-title"> Behavior Change </h5>
                                <p class="thumbnail-subtitle"> design research</p>
                            </a>
                        </div>
                    </div>
</div>

【问题讨论】:

标签: css twitter-bootstrap flexbox alignment bootstrap-4


【解决方案1】:

您应该使用rowcol-*s 并使用d-blockmx-auto 类在列的中心对齐imgs。

&lt;img class="thumbnail img-fluid d-block mx-auto" src="images/wanderlust.jpg" /&gt;

d-block 将其显示设置为blockmx-auto 将其margin-leftmargin-right 设置为auto

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-05
    • 1970-01-01
    • 2020-10-02
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多