https://codepen.io/Eugene-73/pen/mybEbMW
body {
display: flex;
}
.section {
width: 1260px;
}
.speakers {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.speaker {
width: 418px;
/* Если поставить 420px то 3 столбец съедет вниз, почему так??? Эти 2 пикселя от бордера, почему эти пискели не входят в 420px????*/
box-sizing: border-box;
/* Почему не работает????*/
display: block;
}
<section class="section">
<h2 class="section-title">Наши эксперты</h2>
<div class="speakers">
<div class="speaker">
<img src="https://netology-code.github.io/html-2-homeworks/block-elements-positioning/our-experts-section/img/6211.jpg" class="speaker-photo" alt>
<span class="speaker-name">Татьяна Тен</span>
</div>
<div class="speaker">
<img src="https://netology-code.github.io/html-2-homeworks/block-elements-positioning/our-experts-section/img/18702.jpeg" class="speaker-photo" alt>
<span class="speaker-name">Денис Ежков</span>
</div>
<div class="speaker">
<img src="https://netology-code.github.io/html-2-homeworks/block-elements-positioning/our-experts-section/img/18292.jpeg" class="speaker-photo" alt>
<span class="speaker-name">Андрей Батусов</span>
</div>
<div class="speaker">
<img src="https://netology-code.github.io/html-2-homeworks/block-elements-positioning/our-experts-section/img/16689.jpeg" class="speaker-photo" alt>
<span class="speaker-name">Александр Беспоясов</span>
</div>
<div class="speaker">
<img src="https://netology-code.github.io/html-2-homeworks/block-elements-positioning/our-experts-section/img/9998.jpeg" class="speaker-photo" alt>
<span class="speaker-name">Константин Фокин</span>
</div>
<div class="speaker">
<img src="https://netology-code.github.io/html-2-homeworks/block-elements-positioning/our-experts-section/img/19697.jpeg" class="speaker-photo" alt>
<span class="speaker-name">Виталий Гусаров</span>
</div>
</div>
</section>
The problem is that box-sizing: border-box does not work; and the blocks shift down if you set the width to 420px
If you set the width to 420px, the blocks shift downwards, Why is that??
How can this be explained?
2
Answers
Actually, you can explain this issue as box-sizing: border-box not working.
The solution you’re seeking is as follows.
You need to add following piece of code.
Found something through digging around in webtools:
Your containter
.speakers
itself isn’t wide enough, as it’s border takes 6px from it.I tried to add
box-sizing:border-box
to.speakers
, but it didn’t fix it (probably because of the flexbox).This workaround should get the job done:
preview (open it full page):