本文介绍了引导行中的水平可滚动 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个水平滚动的引导行.该行包含包裹在 div 中的客户评论.每个推荐div的宽度为33.333%.

white-space: nowrapdisplay: inline-block 不起作用.

我做错了什么?

<div class="col-lg-12 text-center"><div class="section-title"><div class="testimonial_group"><div class="testimonial">...</div><div class="testimonial">...</div><div class="testimonial">...</div><div class="testimonial">...</div>...

解决方案

请检查.这是你想要达到的目标吗?

CodePenJSFiddle

/* 事情的核心 */.testimonial-group >.排 {溢出-x:自动;空白:nowrap;}.testimonial-group >.row >.col-xs-4 {显示:内联块;浮动:无;}/* 装饰 */.col-xs-4 { 颜色:#fff;字体大小:48px;填充底部:20px;填充顶部:18px;}.col-xs-4:nth-child(3n+1) { 背景:#c69;}.col-xs-4:nth-child(3n+2) { 背景:#9c6;}.col-xs-4:nth-child(3n+3) { 背景:#69c;}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><div class="container testimonial-group"><div class="row text-center"><div class="col-xs-4">1</div><!----><div class="col-xs-4">2</div><!----><div class="col-xs-4">3</div><!----><div class="col-xs-4">4</div><!----><div class="col-xs-4">5</div><!----><div class="col-xs-4">6</div><!----><div class="col-xs-4">7</div><!----><div class="col-xs-4">8</div><!----><div class="col-xs-4">9</div>

对于 Bootstrap 4

感谢 Hector评论

https://codepen.io/glebkema/pen/xxOgaMm

/* 事情的核心 */.testimonial-group >.排 {显示:块;溢出-x:自动;空白:nowrap;}.testimonial-group >.row >.col-4 {显示:内联块;}/* 装饰 */.col-4 { 颜色:#fff;字体大小:48px;填充底部:20px;填充顶部:18px;}.col-4:nth-child(3n+1) { 背景:#c69;}.col-4:nth-child(3n+2) { 背景:#9c6;}.col-4:nth-child(3n+3) { 背景:#69c;}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css"><div class="container testimonial-group"><div class="row text-center"><div class="col-4">1</div><!----><div class="col-4">2</div><!----><div class="col-4">3</div><!----><div class="col-4">4</div><!----><div class="col-4">5</div><!----><div class="col-4">6</div><!----><div class="col-4">7</div><!----><div class="col-4">8</div><!----><div class="col-4">9</div>

I'm trying the make a horizontal scrollable bootstrap row. The row contains customer reviews wrapped in div's. The width of each testimonial div is 33.333%.

white-space: nowrap and display: inline-block doesn't work.

What am I doing wrong?

<div class="row">
    <div class="col-lg-12 text-center">
        <div class="section-title">
           <div class="testimonial_group">
               <div class="testimonial">...</div>
               <div class="testimonial">...</div>
               <div class="testimonial">...</div>
               <div class="testimonial">...</div>
               ...
           </div>
        </div>
    </div>
</div>
解决方案

Please check. Is it what you want to achieve?

CodePen  • JSFiddle

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

/* Decorations */
.col-xs-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; }
.col-xs-4:nth-child(3n+1) { background: #c69; }
.col-xs-4:nth-child(3n+2) { background: #9c6; }
.col-xs-4:nth-child(3n+3) { background: #69c; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

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

for Bootstrap 4

Thanks Hector for the comment!

https://codepen.io/glebkema/pen/xxOgaMm

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

/* Decorations */
.col-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; }
.col-4:nth-child(3n+1) { background: #c69; }
.col-4:nth-child(3n+2) { background: #9c6; }
.col-4:nth-child(3n+3) { background: #69c; }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css">

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

这篇关于引导行中的水平可滚动 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:45