Я бы сделал два раздела. Скажите header
и section
. Заголовок получает фон и padding-bottom
. Карты находятся в контейнере раздела и получают ОТРИЦАТЕЛЬНЫЙ margin-top
, равный заполнению карты + высоте текста.
Таким образом, вы можете добавить столько, сколько хотите в заголовок, и он будет всегда pu sh другие вещи вниз.
body {
margin:0;
padding:0;
font-family: Arial, Helvetica;
background-color: blue;
}
header {
background-color: red;
color: white;
margin: 0;
padding: 10px 10px 50px 10px;
}
.tiles {
/* this is the important part. Make sure top margin = top padding + height of text */
margin: -25px 10px 0 10px;
display:flex;
justify-content: space-between;
}
.tile {
flex-basis: 25%;
background-color: white;
border-radius: 5px;
padding: 10px;
min-height: 100px;
}
<header>
<h2>Some Header Content</h2>
</header>
<section>
<div class="tiles">
<div class="tile">Tile Content</div>
<div class="tile">Tile Content</div>
<div class="tile">Tile Content</div>
</div>
</section>