Flexbox与垂直溢出的结合无法正常工作

发布于 2025-02-06 12:16:00 字数 5337 浏览 2 评论 0原文

我有一个数小时的问题,我只是可以弄清楚如何修复它。

我创建了一张卡(类似于Bootstrap中的卡)。我给了它一个固定的高度。一切都很好。

但是,在卡内。我有一个DIV,其中有一个称为“交易线”的类。在其中,您在Div内有几条线条。可能有1-50。

我要做的是使溢出-Y工作,因此,如果“事务线” DIV的高度大于卡的固定高度,它将触发滚动模式(溢出y:scroll )。

如果您现在查看它,它不会正确触发滚动模式。如果您从小提琴中删除了几条评论行,则看起来正常。

https://codepen.io/docrow10/pen/pen/pen/pen/pen/mwqplzo

<div class="test-card style-one main-details" style="height: 34vh;">
    <div class="card-main-content">
        <div class="card-main-content-container">
            <div class="content-container">
                <section class="tab-section">
                    <div class="transaction-lines">
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>

                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </div>
    <div class="card-footer-container">
        <div class="card-footer">
            <button class="primary-button">Button</button>
            <button class="primary-button">Button</button><button class="primary-button">Button</button><button
                class="primary-button">Button</button><button class="primary-button">Button</button><button
                class="primary-button">Button</button><button class="primary-button">Button</button>
        </div>
    </div>
</div>

任何帮助都将不胜好。

谢谢。

I have an issue that has been bugging me for hours and I just can figure out how to fix it.

I have created a card (similar to the ones in Bootstrap). I have given it a fixed height. That's all fine.

However, inside the card. I have a div, with a class called "transaction-lines". In it, you have several individual lines inside the div. There could be 1-50.

What I am trying to do is to get the overflow-y working, so that if the height of the "transaction-lines" div is bigger than the fixed height of the card, it will trigger the scroll mode (overflow-y: scroll).

If you look at it now, it doesn't trigger scroll mode correctly. If you remove a few comment lines, from the fiddle, it will look normal.

https://codepen.io/DocRow10/pen/MWQPLzo

<div class="test-card style-one main-details" style="height: 34vh;">
    <div class="card-main-content">
        <div class="card-main-content-container">
            <div class="content-container">
                <section class="tab-section">
                    <div class="transaction-lines">
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>

                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                        <div class="line">
                            <div class="indicator">
                                <div></div>
                                <div></div>
                                <div></div>
                                <div></div>
                            </div>
                            <div>
                                Test Comment Line
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </div>
    <div class="card-footer-container">
        <div class="card-footer">
            <button class="primary-button">Button</button>
            <button class="primary-button">Button</button><button class="primary-button">Button</button><button
                class="primary-button">Button</button><button class="primary-button">Button</button><button
                class="primary-button">Button</button><button class="primary-button">Button</button>
        </div>
    </div>
</div>

Any help would be appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谈情不如逗狗 2025-02-13 12:16:00

我认为下面的说明将为您提供所需的内容:

  1. 从.test-card删除高度属性

  2. 将最大高点属性添加到.card-main-content(例如:最大高点:150px;)

  3. 将以下CSS添加到.Card-Main-Content:

    溢出:隐藏;
    溢出Y:自动;

  4. 从.tab部分删除CSS

想法是,您可以定义可滚动区域的高度。您不会在容器上设置高度,而是在其中添加可滚动区域。

I think the instructions below will give you what you're looking for:

  1. Remove height property from .test-card

  2. Add max-height property to .card-main-content (ex: max-height: 150px;)

  3. Add the following CSS to .card-main-content:

    overflow: hidden;
    overflow-y: auto;

  4. Remove CSS from .tab-section

The idea is that you wan the height of your scrollable area to be defined. You don't set a height on a container and add a scrollable area inside it.

心在旅行 2025-02-13 12:16:00

我自己想出了这一点,部分要感谢上面的@mdurchholz,但是正是.card-main-content本身溢出,而不是.Transaction-line。对父母的子元素(.card-main-content)是您设置高度(.test-card)的是需要溢出属性的,而不是其中一个孩子。

为了解决这个问题,我必须使.content-container成为.Test卡的直接孩子,然后在此处应用溢出的预言。在.CONTENT-CONTAINER中添加了flex:1,因此它将拉伸.Test卡的剩余垂直空间。如果您在.content-container中有很多内容,那么现在将滚动即可激活,而无需移动任何其他内容,这正是我所需要的。

Flexbox与此问题无关。

谢谢,我希望这对将来的人有帮助。

I've figured this out myself, partially thanks to @mdurchholz above, but it was the .card-main-content itself that was overflowing, not the .transaction-lines. The child element (.card-main-content) to the parent you've set the height on (.test-card), is the one that needs the overflow property and not one of it's children.

To resolve this, I had to make the .content-container a direct child of the .test-card and then apply the overflow proprety there. Added flex: 1 to the .content-container, so it would stretch the remaining vertical space of the .test-card. If you have a lot of content in the .content-container, scrolling will now activate, without moving any of the other content, which is exactly what I needed.

Flexbox wasn't relevant to this issue.

Thanks and I hope this is helpful to someone in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文