You can override align-items
with align-self
for a flex item. I am looking for a way to override justify-content
for a flex item.
If you had a flexbox container with justify-content:flex-end
, but you want the first item to be justify-content: flex-start
, how could that be done?
To add to this answer, justify-self is simply not supported in flexbox because it justifies all its items as a group.
The "space-evenly" value for the justify-content property distributes the space between items evenly. It is similar to space-around but provides equal instead of half-sized space on the edges. Can be used in both CSS flexbox & grid.
You may use margin instead align-items and/or justify-content .
There doesn't seem to be justify-self
, but you can achieve similar result setting appropriate margin
to auto
¹. E. g. for flex-direction: row
(default) you should set margin-right: auto
to align the child to the left.
.container { height: 100px; border: solid 10px skyblue; display: flex; justify-content: flex-end; } .block { width: 50px; background: tomato; } .justify-start { margin-right: auto; }
<div class="container"> <div class="block justify-start"></div> <div class="block"></div> </div>
¹ This behaviour is defined by the Flexbox spec.
AFAIK there is no property for that in the specs, but here is a trick I’ve been using: set the container element ( the one with display:flex
) to justify-content:space-around
Then add an extra element between the first and second item and set it to flex-grow:10
(or some other value that works with your setup)
Edit: if the items are tightly aligned it's a good idea to add flex-shrink: 10;
to the extra element as well, so the layout will be properly responsive on smaller devices.
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