同一行引导程序中的多个div

时间:2016-12-06 11:06:54

标签: css twitter-bootstrap

我想在溢出选项的同一行中使用多个div。

.col-xs-3 a{height:100px;background:pink;display:block;margin-top:10px;padding:10px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="col-xs-12">
    <div class="col-xs-3"><a>content1</a></div>
    <div class="col-xs-3"><a>content2</a></div>
    <div class="col-xs-3"><a>content3</a></div>
    <div class="col-xs-3"><a>content4</a></div>
    <div class="col-xs-3"><a>content5</a></div>
    <div class="col-xs-3"><a>content6</a></div>
</div>

1 个答案:

答案 0 :(得分:0)

您需要添加white-space: nowrap并将元素设为inline。添加一些宽度以使溢出限制在当前元素:

.col-xs-12 {
  white-space: nowrap !important;
  max-width: 100%;
  overflow: auto;
}
.col-xs-3 {
  float: none !important;
  display: inline-block !important;
}
.col-xs-3 a {
  height: 100px;
  background: pink;
  display: block;
  margin-top: 10px;
  padding: 10px
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="col-xs-12">
  <div class="col-xs-3"><a>content1</a></div>
  <div class="col-xs-3"><a>content2</a></div>
  <div class="col-xs-3"><a>content3</a></div>
  <div class="col-xs-3"><a>content4</a></div>
  <div class="col-xs-3"><a>content5</a></div>
  <div class="col-xs-3"><a>content6</a></div>
</div>