I would like to use css columns to arrange a list of items into three columns. When I click on certain items, I will use JS to expand them, and when that happens I don’t want the layout be adjusted to compensate. Is this possible?
$('.clickme').click(function(){
$(this).toggleClass('big');
});
/* relevant CSS */
ul{
display:block;
max-width:640px;
list-style:none;
margin:0;
padding:0;
}
.box1 ul{
columns: 200px 3;
}
.box1 li{
break-inside: avoid;
}
.box2 ul{
width: 200px;
float: left;
}
li{
display:block;
background-color:#555;
color:white;
border: 1px solid white;
padding: 4px;
min-height:1px;
}
/* less relevant CSS */
body{font-family: sans-serif;}
.clickme{
transition: min-height .5s;
}
.clickme:hover{
background-color:#999;
cursor: pointer;
}
.clickme.big{
min-height:100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="box1">
<h3>I don't want this - when an element expands the other elements rearrange themselves.</h3>
<ul>
<li>item</li>
<li>item</li>
<li>some of these items are longer than others</li>
<li>item</li>
<li>some of these items are longer than others</li>
<li>item</li>
<li class="clickme">click me</li>
<li>item</li>
<li>item</li>
<li>some of these items are longer than others</li>
<li>item</li>
<li>item</li>
</ul>
</div>
<div class="box2">
<h3>This is what I want - when an element expands the other elements stay put. I'm using multiple lists for this though, and I'd like to use just one list if possible.</h3>
<ul>
<li>item</li>
<li>item</li>
<li>some of these items are longer than others</li>
<li>item</li>
</ul>
<ul>
<li>some of these items are longer than others</li>
<li>item</li>
<li class="clickme">click me</li>
<li>item</li>
</ul>
<ul>
<li>item</li>
<li>some of these items are longer than others</li>
<li>item</li>
<li>item</li>
</ul>
</div>
Here's the CSS I'm using for the columns:
.box1 ul{
columns: 200px 3;
}
Here's a codepen to illustrate - http://codepen.io/anon/pen/YNpJYG
Note: It’s obviously less ideal, but if it’s possible to have CSS columns create the columns based on the number of elements rather than their size, that could work for me.