【问题标题】:Bootstrap 4 nested rows with same heightBootstrap 4个具有相同高度的嵌套行
【发布时间】:2019-10-24 04:59:17
【问题描述】:

认为这个要求很简单:结果应该是一个包含两个主题的非常基本的登录页面。每个主题都有一个子主题。 在移动设备上,应该只有一列连续包含 Topic1、Subtopic1、Topic2、Subtopic2。 在桌面上,主题应并排显示,子主题应垂直对齐。

<div class="container-fluid">

<!-- Subtitles are on the same height but the order on mobile is wrong -->
    <div class="row">
        <div class="col-md-6">
            <h1>Topic 1</h1>
            <p>Four lines of text<br>Line2<br>Line3<br>Line4</p>
        </div>
        <div class="col-md-6">
            <h1>Topic 2</h1>
            <p>Two lines of text<br>Line2</p>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <h2>Subtopic 1</h2>
            <p>Number of lines<br>do not matter</p>
        </div>
        <div class="col-md-6">
            <h2>Subtopic 2</h2>
            <p>But Subtopic 1 and Subtopic 2 should be<br>vertically aligned while >=md<br>and when <md, Subtopic 1 shold be below Topic 1, not below Topic 2</p>
        </div>
    </div>

<hr>

<!-- Display on mobile is correct but subtitles on desktop are not aligned anymore -->
    <div class="row">
        <div class="col-md-6">
            <h1>Topic 1</h1>
            <p>Four lines of text<br>Line2<br>Line3<br>Line4</p>
            <div class="row">
                <div class="col">
                    <h2>Subtopic 1</h2>
                    <p>Number of lines<br>do not matter</p>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <h1>Topic 2</h1>
            <p>Two lines of text<br>Line2</p>
            <div class="row">
                <div class="col">
                    <h2>Subtopic 2</h2>
                    <p>But Subtopic 1 and Subtopic 2 should be<br>vertically aligned while >=sm<br>and when <sm, Subtopic 1 shold be below Topic 1, not below Topic 2</p>
                </div>
            </div>
        </div>
    </div>

</div>

我很惊讶我不知道如何解决这个问题。任何提示都非常感谢。

【问题讨论】:

    标签: html css responsive-design bootstrap-4


    【解决方案1】:

    一种方法是使用 Bootstrap 中的 order 实用程序类并将所有元素的标记调整为同一级别:

    <div class="container-fluid">
        <div class="row">
            <div class="order-0 order-md-0 col-md-6">
                <h1>Topic 1</h1>
                <p>Four lines of text<br>Line2<br>Line3<br>Line4</p>
            </div>
            <div class="order-2 order-md-1 col-md-6">
                <h1>Topic 2</h1>
                <p>Two lines of text<br>Line2</p>
            </div>
            <div class="order-1 order-md-2 col-md-6">
                <h2>Subtopic 1</h2>
                <p>Number of lines<br>do not matter</p>
            </div>
            <div class="order-3 order-md-3 col-md-6">
                <h2>Subtopic 2</h2>
                <p>But Subtopic 1 and Subtopic 2 should be<br>vertically aligned while &gt;=md<br>and when &lt;md, Subtopic 1
                        shold be below Topic 1, not below Topic 2</p> </div> </div> <hr>
            </div>
        </div>
    </div>
    

    查看文档here

    另一种方法是为您的主题列设置预定义的固定高度,或者获取最高主题高度并在页面加载和窗口调整大小时使用 JavaScript 将其设置为所有其他高度。

    【讨论】:

    • 多么尴尬 - 我已多次阅读有关订单的文档,但未能认识到解决方案就在那里......就像一个魅力,非常感谢!
    • 不客气@Ambix。考虑到 HTML 标记也需要更改,不会觉得尴尬!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    • 2020-02-03
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 2023-01-13
    相关资源
    最近更新 更多