1
I will have several accordions on the site, according to the categories, then I put them side by side, only when I click on one of the accordions, the ones that this side generates an undesirable spacing, I wanted to know how to solve this
HTML
<div class="seg-nt">
<div class="caixa">
<span class="open-nt">esportes</span>
<div class="contentNT hide">
01
</div>
</div>
<div class="caixa">
<span class="open-nt">politica</span>
<div class="contentNT hide">
02
</div>
</div>
<div class="caixa">
<span class="open-nt">policial</span>
<div class="contentNT hide">
03
</div>
</div>
CSS
.show{display: block;}
.hide{display: none;}
.seg-nt{
padding: 00.80906148867314% 00.80906148867314%;
width: 100%;
overflow: hidden;
box-sizing: border-box;
}
.seg-nt .caixa{
position: relative;
float: left;
margin: 0% 00.80906148867314% 00.80906148867314% 0%;
padding: 00.80906148867314% 00.80906148867314%;
width: 49.55555555555555%;
border: 1px solid #e1e1e1;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.seg-nt .caixa:nth-child(-n+2){margin: 0% 00.80906148867314% 00.80906148867314% 0%;}
.seg-nt .caixa:nth-child(2n){margin: 0% 0% 00.80906148867314% 0%;}
.seg-nt .caixa:last-child{margin: 0%;}
.seg-nt .caixa span{
position: relative;
display: block;
width: 100%;
height: 30px;
line-height: 30px;
font-size: 1.3em;
text-align: center;
text-transform: uppercase;
cursor: pointer;
}
.seg-nt .caixa .contentNT{
float: left;
height: 150px;
border-top: 1px solid #e1e1e1;
background-color: orange
}
JQUERY
$(function(){
$('.open-nt').click(function(){
var contentNT = $(this).parent().find('.contentNT');
if(!contentNT.hasClass('show')){
$('.caixa').find('.show').slideUp('fast', function(){
$(this).addClass('hide').removeClass('show');
});
contentNT.slideDown('fast', function(){
$(this).addClass('show').removeClass('hide');
});
}
});
});
And what would this unwanted space be? How do you want the behavior to be when one of them is open?
– hugocsl
@hugocsl opa Ugo, I edited the image, when the sports accordion is open, the finance accordion would have to go up and fill that space, and so for all the accordions, whichever is open
– goio
Dude I tried to simulate your problem here but the question code is too far away from what’s in the image you posted... Are you using Bootstrap-like framewrok? Or is this "accordion" of yours some jQuery plug-in with extra CSS and everything in between?
– hugocsl
opa Hugo, only has the jquery library in it, looks at the problem here https://jsfiddle.net/moya2018/Lhcz2e7p/14/
– goio