css - Bootstrap 4水平滚动div

标签 css twitter-bootstrap bootstrap-4 twitter-bootstrap-4 twitter-bootstrap-4-beta

我得到这个适用于 Bootstrap 3,但相同的代码在 Bootstrap 4 中不起作用。

基本上,我正在尝试为 DIV 创建一个水平滚动,这是一个适用于 Bootstrap 3 的工作 JSFIDDLE(我不想要):DEMO

Bootstrap 4 的相同代码不起作用!这是 Bootstrap 4 的 JSFiddle:https://jsfiddle.net/6kvw2q5h/

HTML

<div class="live__scroll">
  <div class="row text-center">
    <div class="col-8 live__scroll--box">1</div>
    <div class="col-8 live__scroll--box">1</div>
    <div class="col-8 live__scroll--box">1</div>
    <div class="col-8 live__scroll--box">1</div>
    <div class="col-8 live__scroll--box">1</div>
    <div class="col-8 live__scroll--box">1</div>
    <div class="col-8 live__scroll--box">1</div>
    </div>
</div>

CSS
.live__scroll {
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}
.live__scroll .live__scroll--box {
  display: inline-block;
  float: none;
  padding: 15px;
  border: 1px solid red;
}

我究竟做错了什么?我无计可施。

最佳答案

HTML

<div class="container testimonial-group">
    <div class="row text-center flex-nowrap">
        <div class="col-sm-4">1</div>
        <div class="col-sm-4">2</div>
        <div class="col-sm-4">3</div>
        <div class="col-sm-4">4</div>
        <div class="col-sm-4">5</div>
        <div class="col-sm-4">6</div>
        <div class="col-sm-4">7</div>
        <div class="col-sm-4">8</div>
        <div class="col-sm-4">9</div>
    </div>
</div>

CSS
/* The heart of the matter */
.testimonial-group > .row {
  overflow-x: auto;
  white-space: nowrap;
}
.testimonial-group > .row > .col-sm-4 {
  display: inline-block;
  float: none;
}

/* Decorations */
.col-sm-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; }
.col-sm-4:nth-child(3n+1) { background: #c69; }
.col-sm-4:nth-child(3n+2) { background: #9c6; }
.col-sm-4:nth-child(3n+3) { background: #69c; }

注意:codepen

关于css - Bootstrap 4水平滚动div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47733537/

相关文章:

css - Bootstrap 无法识别移动设备中的两个菜单导航

javascript - Jquery ui 对话框按钮不适用于 bootstrap

c# - ASP.Net Core 客户端验证 : is there a "validation succeeded" DOM event?

css - 使用 HTML5 和 Bootstrap Select 选择的不同高度

javascript - 在 jquery 中追加行时重复

html - css:50% 宽度 div 之间的 20px 间距

css - JQuery 移动版 : Replace thumbnail with data element

bootstrap-maven 类的 css 类覆盖

html - 在不影响另一个 DIV 的情况下向 DIV 添加 margin top

html - 屏幕调整大小时,单行显示的等宽图像不会停留在同一行