[英]Bootstrap - Auto expanding container, row & row columns' width with content
I have following html: 我有以下HTML:
<div class="container">
<div class="row">
<div class="col-md-6">
<ul>
<li>Long Content 1<li>
</ul>
</div>
<div class="col-md-6">
<ul>
<li>Long Content 2<li>
</ul>
</div>
</div>
</div>
I will be adding dynamic content into each ul element. 我将在每个ul元素中添加动态内容。 I want col-md-* elements and their parents to expand themselves horizontally with the content, even if they horizontally overflow the screen window.
我希望col-md- *元素及其父元素随内容水平扩展,即使它们水平溢出屏幕窗口也是如此。 I don't mind horizontal scrolling on the screen.
我不介意在屏幕上水平滚动。 How can I achieve this?
我该如何实现?
You can use the display:inline-block
property of css for the li. 您可以将css的
display:inline-block
属性用作li。 Please see the example below: 请参见以下示例:
ul li{ display:inline-block; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div class="container"> <div class="row"> <div class="col-md-6"> <ul> <li>Long Content 1<li> <li>Long Content 1<li> <li>Long Content 1<li> <li>Long Content 1<li> <li>Long Content 1<li> <li>Long Content 1<li> <li>Long Content 1<li> <li>Long Content 1<li> <li>Long Content 1<li> </ul> </div> <div class="col-md-6"> <ul> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> <li>Long Content 2<li> </ul> </div> </div> </div>
将container
更换为container-fluid
This will force the element to NEVER wrap text and should help with what you're looking for. 这将迫使该元素永远不要换行,并且可以帮助您寻找所需的内容。
li{white-space:nowrap}
You may need to change the li element to display:block as well 您可能还需要将li元素更改为display:block
I have been playing around with this a bit. 我一直在玩这个。 I ended up with this: JSFiddle .
我最后得到了这个: JSFiddle 。 I didn t manage to get bootstrap loaded properly so I added in some css to replicate the bootstrap .col-md-6 behavior.
我没有设法正确加载引导程序,所以我添加了一些CSS以复制引导程序.col-md-6行为。 I basically added white-space: nowrap to the li-items.
我基本上在空白项目中添加了空白:nowrap。 And also enabled vertical scrolling on the divs.
并且还启用了div上的垂直滚动。 I figured that would be about what you wanted to do.
我认为这与您想做的事情有关。
html HTML
<div class="container">
<div class="row">
<div class="col-md-6 scrollbox">
<ul>
<li>Long Content 1 nkjdfhkjfh dskjfhdkjs hkjdsh fkjdshkjf hdkjshf kjh fkdsk fjhkj dhfkjshfkj das fdkjsfkjdsfkj hks fkadsj f last word<li>
</ul>
</div>
<div class="col-md-6 scrollbox">
<ul>
<li>Long Content 2<li>
</ul>
</div>
</div>
</div>
css CSS
li{
white-space: nowrap;
}
/*col-md-6 code is to simulate bootstrap*/
.col-md-6{
width: 50%;
float: left;
}
.scrollbox{
background-color: rgb(200,200,220);
overflow-x: auto;
overflow-y: auto;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.