简体   繁体   English

引导布局行具有不同的高度

[英]bootstrap layout row with different heights

i want to add bootstrap row with col-lg-3 class. 我想用col-lg-3类添加bootstrap行。 my div contains different heights.hope to add articles with different length texts. 我的div包含不同的高度。添加具有不同长度文本的文章。 my output is but designed expected output and here. 我的输出是设计的预期输出和这里。 code as follows 代码如下

<div class="row">
    <div class="col-lg-3" style="background-color: #c5d5cb"><p style="height: 150px">1</p></div>
    <div class="col-lg-3" style="background-color: #9fa8a3"><p style="height: 200px">2</p></div>
    <div class="col-lg-3" style="background-color: #e3e0cf"><p style="height: 50px">3</p></div>
    <div class="col-lg-3" style="background-color: #b3c2bf"><p style="height: 60px">4</p></div>  

    <div class="col-lg-3" style="background-color: #173e43"><p style="height: 44px">5</p></div>
    <div class="col-lg-3" style="background-color: #b56969"><p style="height: 70px">6</p></div>
    <div class="col-lg-3" style="background-color: #daad86"><p style="height: 20px">7</p></div>
    <div class="col-lg-3" style="background-color: #5a5c51"><p style="height: 35px">8</p></div> 
</div>

Updated values put as 1,2,3 etc comes from mysql database. 更新的值为1,2,3等来自mysql数据库。 so the height is equal to text row numbers. 所以高度等于文本行号。 php code is follows ` php代码如下`

    foreach ($value as $add) {
        echo "<div class='col-md-3'><p>";
        echo $add->item;
        echo "</p></div>";
    }
    ?>`

Perhaps, I ruin your original code. 也许,我毁了你原来的代码。 I change everywhere. 我无处不在。 I hope this helps you. 我希望这可以帮助你。

  1. Add customized stylesheet inside tag head: 在标记头中添加自定义样式表:

<style> .col-md-3{padding:0px;} // default: 15px -> left and right. </style>

  1. Here's the code: 这是代码:

<div class="container"> <div class="col-md-12"> <div class="col-md-3"> <div class="col-md-12" style="background-color: #c5d5cb;height: 150px;"> 1 </div> <div class="clearfix"></div> <div class="col-md-12" style="background-color: #173e43;height: 44px; color:white;"> 5 </div> </div> <div class="col-md-3"> <div class="col-md-12" style="background-color: #9fa8a3;height: 200px;"> 2 </div> <div class="clearfix"></div> <div class="col-md-12" style="background-color: #b56969;height: 70px;"> 6 </div> </div> <div class="col-md-3"> <div class="col-md-12" style="background-color: #e3e0cf;height: 50px;"> 3 </div> <div class="col-md-12" style="background-color: #daad86;height: 20px;"> 7 </div> </div> <div class="col-md-3"> <div class="col-md-12" style="background-color: #b3c2bf;height: 60px;"> 4 </div> <div class="col-md-12" style="background-color: #5a5c51;height: 35px;"> 8 </div> </div> </div> </div>

Because I don't know what version of your bootstrap, I use v3.1.1 for clearfix ... you can customize this based on your version. 因为我不知道你的引导程序的版本,我使用v3.1.1 for clearfix ...你可以根据你的版本自定义它。

You are on right track. 你走在正确的轨道上。 This will definitely work. 这肯定会奏效。 You need to use col-md-3 like this : 您需要像这样使用col-md-3:

<div class="row">
<div class="col-md-3">
    <p>1</p>
    <p>5</p>
</div>
<div class="col-md-3">
   <p>2</p>
   <p>6</p>
</div>
<div class="col-md-3">
   <p>3</p>
   <p>7</p>
</div>
<div class="col-md-3">
   <p>4</p>
   <p>8</p>
</div>
</div>

I think try this 我想试试这个

<div class="row">
  <div class="col-lg-5">
   <div id="1"  ></div>
   <div id="5"  ></div>
  </div>
<div class="col-lg-5">
   <div id="2"  ></div>
   <div id="6"  ></div>
  </div>
<div class="col-lg-5">
   <div id="3"  ></div>
   <div id="7"  ></div>
  </div>
<div class="col-lg-5">
   <div id="4"  ></div>
   <div id="8"  ></div>
  </div>
</div>

Hope this will help you.. 希望对你有帮助..

You can first use columns with col-lg-3 and then place your blocks inside each one. 您可以先使用col-lg-3列,然后将块放在每个列中。 That way you will get your desired result. 这样你就可以获得理想的结果。

HTML: HTML:

<div class="container">
  <div class="row">
    <div class="col-lg-3 grid-row">
      <div class="left-block" style="background-color: #c5d5cb"><p style="height: 150px">1</p></div>
      <div class="left-block" style="background-color: #173e43"><p style="height: 44px">5</p></div>
    </div>
    <div class="col-lg-3 grid-row">
      <div class="left-block" style="background-color: #9fa8a3"><p style="height: 200px">2</p></div>
      <div class="left-block" style="background-color: #b56969"><p style="height: 70px">6</p></div>
    </div>
    <div class="col-lg-3 grid-row">
      <div class="left-block" style="background-color: #e3e0cf"><p style="height: 50px">3</p></div>
      <div class="left-block" style="background-color: #daad86"><p style="height: 20px">7</p></div>
    </div>
    <div class="col-lg-3 grid-row">
      <div class="left-block" style="background-color: #b3c2bf"><p style="height: 60px">4</p></div>
      <div class="left-block" style="background-color: #5a5c51"><p style="height: 35px">8</p></div>
    </div>
  </div>
</div>

CSS: CSS:

.grid-row{
  margin-left: -15px;
  margin-right: -15px;
}
.left-block{
  float: left;
  width: 100%;
}

Jsfiddle: https://jsfiddle.net/debraj/6dufsc4u/1/ Jsfiddle: https ://jsfiddle.net/debraj/6dufsc4u/1/

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM