Bootstrap将div内容推送到新行

kar*_*ayi 35 html css css3 twitter-bootstrap

不知何故,我无法弄清楚如何完成我的格式化为列表的代码,并需要将其格式化为网格,这是通过javascript切换.

我的HTML代码用于列出内容

<div class="list">
    <div class="row">
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">Right is next DIV</div>
        <div class="col-lg-6 col-md-6 col-sm-5 col-xs-12">Right is next DIV</div>
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">I am the last DIV</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

列表的CSS代码.所有其他CSS都由bootstrap采用

.styled_view div.list {
    padding: 0;
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

应使用相同的代码来显示网格

<div class="grid">
    <div class="row">
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">Under me should be a DIV</div>
        <div class="col-lg-6 col-md-6 col-sm-5 col-xs-12">Under me should be a DIV</div>
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">I am the last DIV</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

网格的CSS

.styled_view div.grid {
    display: inline-block;
    overflow: hidden;
    vertical-align: top;
    width: 19.4%;
}
Run Code Online (Sandbox Code Playgroud)

画廊每个部分的19.4%使DIV紧挨着下一个.它不会将它推向新的一条线.我该怎么解决?

小智 81

做一行div.

像这样

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<div class="grid">
    <div class="row">
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 bg-success">Under me should be a DIV</div>
        <div class="col-lg-6 col-md-6 col-sm-5 col-xs-12 bg-danger">Under me should be a DIV</div>
    </div>
    <div class="row">
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12 bg-warning">I am the last DIV</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)


小智 5

如果您的列表是用未知数字动态生成的,并且您的目标是始终将最后一个 div 放在新行中,请将最后一个 div 类设置为“col-xl-12”并删除其他类,以便它始终占据整行。

这是已更正的代码副本,因此最后一个 div 始终占据一整行(我虽然删除了不必要的类)。

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<div class="grid">
  <div class="row">
    <div class="col-sm-3">Under me should be a DIV</div>
    <div class="col-md-6 col-sm-5">Under me should be a DIV</div>
    <div class="col-xl-12">I am the last DIV and I always take a full row for my self!!</div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)