首页 > 解决方案 > Bootstrap 4 在 div 上使用粘性和浮动

问题描述

我正在使用带有float-leftfloat-right类的 Bootstrap 4,这些类可以使我的 2 个 div 彼此保持左右并且效果很好,但是我希望正确的 divsticky也是如此,但这似乎不起作用。我position-sticky在 div 上使用float-right

浮动类参考此处浮动 URL

粘性类参考位置 URL

基本上我的 HTML 看起来像这样:

<section class="section">
<div class="float-left col-md-8">
    <div class="row sameheight-container">
        <div class="col-md-12">
           @*Form fields, such as input, select etc.*@
        </div>
    </div>
</div>
<div class="float-right col-md-4 position-sticky">
    <div class="row sameheight-container">
        <div class="col-md-12">
            <div class="card card-block sameheight-item">
                <table>
                    <thead>
                        <tr>
                            <th>Quantity</th>
                            <th>Price</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>2</td>
                            <td>3</td>
                            <td>6</td>
                        </tr>
                        <tr>
                            <td>5</td>
                            <td>10</td>
                            <td>50</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

请注意,第一个 Div 有一堆表单控件,所以我已将其删除并在其中添加评论。

有没有办法做到这一点?

谢谢你的帮助!

标签: cssbootstrap-4

解决方案


推荐阅读