Sorry about the title, it's pretty unclear but I didn't know how else to write it.
So basically, im making a pretty simple website with just HTML and CSS. I have these 3 cards that have their own <a> parent element because I wanted them all to be clickable no matter where on the card you clicked them. And then all those elements are wrapped in a div tag called cards
Before I added the anchor tags on the elements, I had centered all the cards by just using flexbox on the cards class in my CSS file. Up to this point all cards were on the same line and were perfectly centered. Now, after wrapping each card in separate anchor tags I applied the same flexbox formatting I had in the cards class to all anchor elements in that div. All good up to this point. But when I delete the flexbox formatting in the cards class, it turns all the cards into block elements even the cards parents which is the anchor tags, have the same flexbox formatting. So why does that happen? I thought flexbox only applied to direct children and not also the grandchildren.
.cards{
display: flex;
justify-content: space-between;
}
.cards a {
display: flex;
text-align: center;
color: white;
text-decoration: none;
margin: 0 1rem;
}
.cards p {
font-size: 0.85rem;
line-height: 1.2rem;
padding: 0 1.25rem;
}
.card1{
background-image: url("images/image-background-card1.jpg");
background-size: cover;
background-position: bottom;
min-height: 200px;
width: 100%;
}
.card2{
background-image: url("images/image-background-card2.jpg");
background-size: cover;
background-position: bottom;
min-height: 15.625rem;
width: 100%;
}
.card3{
background-image: url("images/image-background-card3.jpg");
background-size: cover;
background-position: bottom;
min-height: 15.625rem;
width: 100%;
}
<div class="cards">
<a href="#">
<div class="card1">
<i class="fas fa-motorcycle"></i>
<h2>Book Online</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Itaque hic illum accusantium ratione corporis voluptatem.</p>
</div>
</a>
<a href="#">
<div class="card2">
<i class="fas fa-wrench"></i>
<h2>Service Types</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sunt praesentium placeat sapiente nulla omnis voluptatum!</p>
</div>
</a>
<a href="#">
<div class="card3">
<i class="fas fa-phone-square-alt"></i>
<h2>Call for Advice</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sunt praesentium placeat sapiente nulla omnis voluptatum!</p>
</div>
</a>
</div>
So basically when I remove the .cards stuff in the css file, the elements turn into inline even though each cards parent has the same flexbox formatting inside it which I thought would have made the other css pointless.
Heres the codepen so you can see what I mean. I replaced the images in the cards with background color.codepen