How can I set the first-child of flexbox in full-width and all of the other childs set to flex:1
(for split space)?
Like this:
“For example, if all items have flex-grow set to 1, every child will set to an equal size inside the container. If you were to give one of the children a value of 2, that child would take up twice as much space as the others.”
You can set the :first-child
to a width of 100%
, and the rest of the childs :not(:first-child)
to flex: 1
.
To put them on multiple lines, use flex-wrap: wrap
on the container:
.container { display: flex; justify-content: space-between; flex-wrap: wrap; background: #e2eaf4; padding: 10px; } .child { display: inline-block; font-family: "Open Sans", Arial; font-size: 20px; color: #FFF; text-align: center; background: #3794fe; border-radius: 6px; padding: 20px; margin: 12px; } .child:first-child { width: 100%; } .child:not(:first-child) { flex: 1; }
<div class="container"> <div class="child">Child</div> <div class="child">Child</div> <div class="child">Child</div> </div>
Add width: 100%;
for your first item. And flex: 1;
for others.
.flex { display: flex; flex-wrap: wrap; } .flex-item:not(:first-child) { flex: 1; } .flex-item:nth-child(1) { width: 100%; } /* Styles just for demo */ .flex-item { background-color: #3794fe; margin: 10px; color: #fff; padding: 20px; border-radius: 5px; }
<div class="flex"> <div class="flex-item"> Child </div> <div class="flex-item"> Child </div> <div class="flex-item"> Child </div> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With