加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

jquery – 将每个span标记的div集动态添加到相等的高度

发布时间:2020-12-14 22:35:35 所属栏目:资源 来源:网络整理
导读:我尝试创建此但未设置,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').he

我尝试创建此但未设置,div高度固定为50px和最大跨度
加5

enter image description here

$('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);
          
        }
      }
    );
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;
}