I’m looking for a slightly modified version of the justify-content: center
. Instead of justifying everything in the center I’d like to have one specific item in the center and all around it. Like in the image.
<div class="wraper">
<span>1</span>
<span>2</span>
<span>Centre</span>
<span>3</span>
</div>
.wrapper {
display: flex;
justify-content: center;
}
What the above code does:
What I need:
How to achieve this?
2
Answers
Here is something that does what you want. In this case, the not-centered spans are child elements of the centered
span
, making it possible to apply relative and absolute positions to the elements. The only not-absolute one is the to-be-centered element (or actually its direct contents), the others are positioned in relation to that. Note that this only works if you apply a fixed width to the elements.Here is my best attempt at it (kind of reorganizing the elements a bit).