小编Kap*_*pil的帖子

在div set中将每个span标记中的<span>动态添加到相等的高度

我尝试创建此但未设置,div高度固定为50px,最大跨度为5 在此输入图像描述

$('section.group').each(function() {
        //alert(($(this).find('.item')).length);
        var hig =50;
        
        var total =($(this).find('.item')).length;
        if(total !== 0){
          //alert(hig/total);
          //$('.item').height(hig/total);
          $(this).each('.item').height(hig/total);
          
        }
      }
    );
Run Code Online (Sandbox Code Playgroud)
section.group{
  height:50px;
  margin-bottom:10px;
  overflow:hidden;
  border:1px solid;
}
.item{
  display:block;
}
.item:nth-child(1) {
    background: #ff0000;
}
.item:nth-child(2) {
    background: #00ff00;
}
.item:nth-child(3) {
    background: #0000ff;
}
.item:nth-child(4) {
    background: #000;
}
.item:nth-child(5) {
    background: #f0f000;
}
Run Code Online (Sandbox Code Playgroud)
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<section class="group">
  <span class="item"></span>
  <span class="item"></span>
  <span class="item"></span>

</section>

<section class="group">
  <span class="item"></span>
  <span class="item"></span>
  <span class="item"></span>
  <span class="item"></span>
  <span class="item"></span>

</section>  
  <section class="group"> …
Run Code Online (Sandbox Code Playgroud)

html jquery css3

6
推荐指数
1
解决办法
383
查看次数

标签 统计

css3 ×1

html ×1

jquery ×1