twitter-bootstrap 同一行引导程序中的多个 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40993854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 00:25:22 来源:igfitidea点击:
Multiple div in same line bootstrap
提问by user12345
I want multiple div in same line with overflow option.
我想要多个 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>
回答by Praveen Kumar Purushothaman
You need to add white-space: nowrapalong with making the elements to be inline. Add some width to make the overflow confined to the current element:
您需要添加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>

