【问题标题】:Bootstrap horizontal scroll showing verticalBootstrap 水平滚动显示垂直
【发布时间】:2020-03-08 03:47:22
【问题描述】:

我有这个 div 容器,当有四个以上的项目(项目是带标题的图片)时,我想显示一个水平滚动。

我想要实现的目标:

问题是,当我将代码放在下面时,我得到一个垂直滚动,最后一项(四个之后的下一个)进入新行。

当前结果:

这是 HTML:

<div class="col-xl-10 col-lg-12 col-md-12 col-sm-12 wrapper">
    <div class="row scroll">
            <div class="col-lg-3 col-md-3 col-sm-12 image-holder">
                <div class="image-crop">
                    <img src="../../../../assets/fortress.jpg" class="img-fluid img-file"
                            alt="Responsive image of item">
                    <div class="shadow"></div>
                </div>

                <span class="image-text">Fortress</span>
            </div>
            <div class="col-lg-3 col-md-3 col-sm-12 image-holder"> 
                ... SAME AS ABOVE x4...
            </div>
    </div>
</div>

这是 CSS:

.image-holder {
    position: relative; 
    width: 100%; /* for IE 6 */
}

.image-text {
    position: absolute;
    top: 78%; 
    left: 33%;
    text-align: center;
    color: white;
    font-size: 1.8rem;
}

.image-crop { 
    position: relative;
    margin: 10px;
    float: left;
    -webkit-box-shadow: inset 0 -45px 45px -11px #000000;
    -moz-box-shadow: inset 0 -45px 45px -11px #000000;
    box-shadow: inset 0 -45px 45px -11px #000000;
}

.img-file {
    display: block;
    position: relative;
    z-index: -1;

    height: 270px;
    width: 300px;
    object-fit: cover;
}

/* horizontal scroll */
.wrapper {
    position: relative;
    width: 600px;
}

.scroll {
    overflow-x: scroll;
    overflow-y: scroll;
    height: 250px;
    white-space: normal;
}

最终目标是获得第一张图片中的结果。稍后我将在屏幕为移动视图时将水平滚动更改为垂直。

这是没有 Bootstrap 的 StackBlitz:

https://stackblitz.com/edit/angular-xxuvdx?file=src%2Fapp%2Fapp.component.html

【问题讨论】:

  • 在 .scroll 中设置空白为 nowrap

标签: css twitter-bootstrap bootstrap-4


【解决方案1】:

使用 Bootstrap 4 flex-nowrap 类..

<div class="row scroll flex-nowrap">
...
</div>

https://www.codeply.com/p/mzQRwa2jip

【讨论】:

  • 谢谢 Zim,没有看到 fly-nowrap。快速跟进问题。当我切换到移动视图时,有没有办法可以将其更改为垂直滚动?使用媒体查询?
猜你喜欢
  • 2021-11-13
  • 2014-01-09
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 2018-02-08
  • 1970-01-01
  • 1970-01-01
  • 2018-06-21
相关资源
最近更新 更多