css 固定高度的引导卡,卡文本可垂直滚动

w9apscun  于 2022-11-19  发布在  其他
关注(0)|答案(3)|浏览(198)

如何实现具有可垂直滚动的card-text部分的固定高度bootstrap 4卡?

<div class="card" style="height:300px">        <-- non scrollable
    <div class="card-body">                    <-- non scrollable
        <h5 class="card-title">Card title</h5> <-- non scrollable
        <p class="card-text">This portion and only this portion will have a very long text so much so that the vertical scroll bar may appear when required.</p>
    </div>
</div>
z9smfwbn

z9smfwbn1#

你必须用一个可滚动的容器 Package .card-text,然后设置可滚动的容器overflow-y: auto;
别忘了为可滚动容器设置height。如果height默认为自动,滚动条将不会出现。
https://codepen.io/blackcityhenry/pen/LXOOgW

kse8i1jr

kse8i1jr2#

你需要应用这个CSS

**wrap this**
.card-text { height: 42px; overflow-x: scroll; width: 100%; }

.card-text p { width: 650px; word-break: break-word; }
htrmnn0y

htrmnn0y3#

在css代码中进行水平滚动

<style>
 .card-text { height: 42px; overflow-x: scroll; width: 100%; }
    
 .card-text p { width: 650px; word-break: break-word; }
</style>

在css代码中用于垂直滚动

<style>
 .card-text { height: 42px; overflow-y: scroll; width: 100%; }
    
 .card-text p { width: 650px; word-break: break-word; }
</style>

HTML格式-用于水平滚动/垂直滚动

<div class="card" style="height:300px">        
    <div class="card-body">                    
        <h5 class="card-title">Card title</h5> 
        <p class="card-text">This portion and only this portion will have a very long text so much so that the vertical scroll bar may appear when required.</p>
    </div>
</div>

相关问题