O
O
Outsider V.2017-10-25 15:01:50
css
Outsider V., 2017-10-25 15:01:50

Flex: how to align a block to the center of the parent, regardless of neighbors?

I read about flex, found out that float does not work in it.
How, then, to make the alignment of the first element in the center, and the rest "throw" to the right?

<div class="parent">
  <div class="one">One</div>
  <div class="two">Two</div>
  <div class="three">Three</div>
</div>

.parent {
  display: flex;
  border: 1px solid black;
  justify-content: center;
}

.one, .two, .three {
  display: flex;
  margin: 0 3em;
}

https://jsfiddle.net/prx62yLu/

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Outsider V., 2017-10-25
@Audiophile

Set the central block:
position: absolute;
right: 50%;
transform: translateX(50%);
And the rest aligned to the right.

A
Ankhena, 2017-10-25
@Ankhena

https://jsfiddle.net/n1wn9gvw/

A
Alexander, 2017-10-25
@AlexZaw

https://jsfiddle.net/AlexZaw/jvk7xwpn/
isn't it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question