I'm making 2 columns with CSS Grid and with Collapsible div.
The problem is when I expand the one of the collapsible div,
the other div will also expanding with white space.
Anyone knows how to fix this without making 2 parents div for 2 columns?
Or using other method instead of CSS-grid?
screenshoot css grid with collapsible div
What you're trying to achieve is more of a masonry kind of layout on an expansion of an accordion. That is not something grid is designed for. The CSS Grid is two dimensional so you are always working with rows and columns at the same time.
Solution: Flexbox
#grid {
display: flex;
flex-direction: column;
align-items: flex-start;
flex-wrap: wrap;
justify-content: space-around;
height: max-content;
flex-flow: row wrap;
counter-reset: brick;
}
.cell {
width: 250px;
flex: 1 0 calc(33.333% - 20px);
padding: 20px;
background: #efefef;
}
Please check the demo I have created. https://codepen.io/abhishekrajeshirke/pen/NLzLJJ
Hope it answers your question.
Related
Sorry if this question is obvious and I am missing something. I am creating a site which has a flexbox container with elements inside it that wrap around. I want my items inside the container to stretch to the edge of the container to ensure there is the correct amount of whitespace. I can achieve this by using justify-content: space-between but when there is a row with more than one item and less than four they still must space themselves. How can I fix this problem? I don't want to use flex-start and adjust the margin between the items because that seems inaccurate and a problem for responsiveness. Below is my code for the flex container.
.clothingitems {
display: flex;
flex-flow: wrap;
justify-content: space-between;
width: 100%;
height: 100%;
background: white;
}
.clothingitem {
width: 265px;
height: 450px;
display: flex;
flex-flow: column;
}
There is a live website but beware the page I'm mentioning has not been made responsive. It can be found here: Site here
Thank you.
You could consider using a CSS grid for this, and using media breakpoints to make it responsive, instead of a horizontal flex with wrap. Here is an example of a grid with each column taking up 15% in width and 5% column-gap between them.
<div class="clothingitems">
<div class="clothingitem"></div>
<div class="clothingitem"></div>
...
</div>
.clothingitems {
display: grid;
grid-template-columns: 15% 15% 15% 15% 15%;
column-gap: 5%;
row-gap: 50px;
}
I am using the Vali Admin theme and I am trying to push the last list item in the left sidebar to the bottom.
I have barely used flexbox before so I am not familiar with it at all, but I changed the menu to display: flex and then followed this answer to try to push the last item to the bottom. I am trying to do exactly what the person in that question if after.
These are my modifications to the theme:
.app-menu {
#extend .app-menu;
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: flex-start;
li:last-of-type {
margin-top: auto;
}
}
Working fiddle.
I think the problem is that the menu isn't using as much height as it can.
I would gladly include a working snippet but for the love of my I couldn't figure out how to create a jsfiddle. It doesn't allow local files and it would block my gist. Same with Codepen.
Add the following on .app-sidebar:
display: flex; // make sidebar a flexbox
flex-direction: column; // so it will align column direction
We do the thing above so we can apply flex related styling on the child.
This will make the parent or sidebar a flexbox, then add the following on .app-menu
flex: 1; // this will take all the remaining space on the sidebar
and remove padding-bottom on .app-menu so the last item will stay in the bottom without the padding.
try this
.app-menu {
margin-bottom: 0;
padding-bottom: 40px;
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: flex-start;
height: 100%;
if last item need to be displayed at the bottom of the page. try by setting height:100% to the ul
It's right to do as it described in link you've attached.
But you didn't set 100% height for your ul.
Setting height: 100%; to .app-menu class solves your problem.
Here is the working example based on your code:
https://jsfiddle.net/zewx18ps/1/
This question already has answers here:
One flex/grid item sets the size limit for siblings
(6 answers)
Closed 6 years ago.
I currently have a flexbox layout that looks like this:
The blue is class = "wrap", the orange and all three yellow boxes are contained in two separate class = "wrap_col", and each yellow box is contained in class = "wrap_item".
.wrap {
display: flex;
flex-flow: row wrap;
margin: 0 auto;
}
.wrap_col {
display: flex;
flex-direction: column;
flex: 1 0 auto;
}
.wrap_item {
margin:10px;
display: flex;
flex:1 0 auto;
flex-direction: column;
}
How can I shrink the three yellow boxes' heights down so that it is the same height as the orange box? Can you shrink flexboxes down to the same height as the shortest box?
An easy way to achieve this would be to make sure that the height of both your columns with the .wrap-col class is this same (either set a fixed height or set height: 100% and have them both fill the space of the .wrap element). Then make sure flex-shrink: 1 is set for all flex items to.
.wrap_item {
margin:10px;
display: flex;
flex:1 1 auto;
flex-direction: column;
}
Here is a jsfiddle. Try changing the height of the .wrap element and you can see the boxes resizing to fit.
I'm very new to CSS, and I'm struggling on positioning a flex item (DownloadButton) the way I want it too.
I want to position a flex item a certain way, but my googling skills are failing me.
The current state looks like this:
Icon DownloadButton DeleteButton
What I want is this:
Icon DownloadButton DeleteButton
I thought I could use align-items, but that's for the cross axis. Rather than even spacing, like the normal flex behavior, I want my DownloadButton hugging the DeleteButton at the end. However, my Googling skills have failed me. Help would be greatly appreciated, thanks guys!
I would align the items to the end (for preference) and then adjust the first one.
As pointed out in the comments the end alignment is not necessary as the effect is caused by the margin adjustment.
.parent {
width: 80%;
margin: 1em auto;
border: 1px solid grey;
display: flex;
justify-content: flex-end;
padding: .5em;
}
button:first-child {
margin-right: auto;
}
<div class="parent">
<button>Icon</button>
<button>Download</button>
<button>Delete</button>
</div>
Add these styles to the container:
#flex-container { /*Select Your Flex Container*/
display: flex;
flex-direction: row;
justify-content: space-between;
}
Add these styles for the flexible items:
.flexible-items { /*Select The Children Of The Flex Container*/
flex-grow: 0; /*This Is Default*/
}
#Icon {
flex-grow: 1;
}
If you want some space between the other two flexible items, you can achieve this by multiple methods, 1 being to add some margin and padding styles for their sides.
I have this list ol with items li which are styled as follows:
ol {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
width: 400px;
}
li {
width: 120px;
height: 120px;
}
DEMO
As you can see 3 items fit on one row. Because I'm using justify-content: space-between the first row looks exactly as I want it. However, the second row does not (because it has only two items). I want them to be positioned as if there was a 6th element (no gap between them and left aligned)
Is there anyway I can achieve this with flex box, or should I introduce an invisible 6th element ?
There is no way of achieving what you are asking by using display:flex; and justify-content:space-between;
See here more details: W3C:Axis Alignment: the ‘justify-content’ property
I would recommend using justify-content:center; or justify-content:flex-start; with margins.