A
A
Antonio Vivaldi2018-11-21 15:13:01
css
Antonio Vivaldi, 2018-11-21 15:13:01

How to center an image with flexbox?

How to center an image with flexbox?
That's what I wanted
5bf54b987ee8f243273946.png

<div class="about">
        <div class="abou__item">
          <span>about</span>
          <img src="img/about1.jpg" alt="">
        </div>
        <div class="abou__item">
          <img src="img/about2.jpg" alt="">
          <span>about</span>
        </div>
        <div class="abou__item">
          <span>about</span>
          <img src="img/about3.jpg" alt="">
        </div>
        <div class="abou__item">
          <span>about</span>
          <img src="img/about4.jpg" alt="">
        </div>
    </div>

.about {
  display: flex;
  flex-direction: column;
  align-items: center;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shmatuan, 2018-11-21
@devaloevera

<span>about</span>make it fixed width + add a second on the other side and make it opacity: 0

<div class="abou__item">
  <span>about</span>
  <img src="img/about2.jpg" alt="">
  <span style="opacity: 0;">about</span>
</div>

Then this block will always be the same width, with the picture in the middle

C
coderxx, 2018-11-21
@coderxx

justify-content: center; // центируем по оси х
align-items: center; // центируем по оси у

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question