简体   繁体   English

使用jquery使子div在一行上相等

[英]Make child div equal on a row using jquery

I need to make the childs div equal to each other how matter long it is together with the column.我需要让孩子们的 div 彼此相等,它与列在一起的时间有多长。 I only have one row then the rest will be a columns out of bootstrap.我只有一行,其余的将是引导程序之外的一列。

This is the fiddle I have created这是我创建的小提琴

http://jsfiddle.net/Qr48S/60/ http://jsfiddle.net/Qr48S/60/

I already making it equal but my problem is that the script is getting the highest div and applying it to the other columns which making the other columns having a big white space whenever it has not that long content.我已经使它相等,但我的问题是脚本正在获取最高的 div 并将其应用于其他列,这使得其他列在没有那么长的内容时具有很大的空白。 What I need is getting it per row though I'm not declaring more than one row.我需要的是每行获取它,尽管我没有声明不止一行。

Button also needs at the bottom of the column按钮也需要在列的底部

It looks like this看起来像这样

<div class="container">
  <div class="row">
    <div class="item-container col-lg-4 col-md-4 col-sm-4">
      <div class="image"><img class="img-responsive"  
      src="http://placehold.it/350x150"></div>
      <div class="item-title"> 
         title title title title title title title 
         title title title title title title title title title 
      </div>
      <div class="item-details"> 
        <p>details 1</p>
        <p>details 2</p>
        <p>details 3</p>
        <p>details 4</p>
      </div>
      <div class="item-button"> 
         <button type="button" class="btn btn-primary">Add to cart</button> 
      </div>
      </div>

      <div class="item-container col-lg-4 col-md-4 col-sm-4">
      <div class="image"><img class="img-responsive"  
      src="http://placehold.it/350x150"></div>
      <div class="item-title"> 
         title title title title title title title 
         title title title title title title title title title
         title title title title title title title 
         title title title title title title title title title 
      </div>
      <div class="item-details"> 
        <p>details 1</p>
        <p>details 2</p>
        <p>details 3</p>
        <p>details 4</p>
        <p>details 1</p>
        <p>details 2</p>
        <p>details 3</p>
        <p>details 4</p>
      </div>
      <div class="item-button"> 
         <button type="button" class="btn btn-primary">Add to cart</button> 
      </div>
      </div>
   </div> 
</div>

My recommendation would be to use the match height plugin我的建议是使用匹配高度插件

I've pasted it into this fork of your jsfiddle我已经将它粘贴到你的 jsfiddle 的这个分支中

http://jsfiddle.net/n2e4wg76/ http://jsfiddle.net/n2e4wg76/

You can then see that it would make it simpler.然后你可以看到它会让它变得更简单。 Of course instead of pasting the whole js file you would include the js file from https://github.com/liabru/jquery-match-height当然,不是粘贴整个 js 文件,而是包含来自https://github.com/liabru/jquery-match-height的 js 文件

then just use然后只需使用

$(document).ready(function() {

    $('.item-container').matchHeight();

});

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

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