I am trying to add ribbon over div of cards in my html page, but it is displacing the div below it. Could anyone help me on how to solve it?
The ribbon is displacing the first card and pushing it down.
.ribbon {
background-color: #a00;
position: relative;
left: -0px;
top: 40px;
height: fit-content;
transform: rotate(-45deg);
}
.ribbon p {
color: #fff;
font: bold 100% 'Helvetica Neue', Helvetica, Arial, sans-serif;
margin: 1px;
padding: 1px 10px;
text-align: center;
text-decoration: none;
}
<div class="main">
<ul class="cards">
<div class="ribbon">
<p>Best value pack</p>
</div>
<li class="cards_item">
<div class="card">
<div class="card_image"><img src="https://via.placeholder.com/50"></div>
<div class="card_content">
<p class="card_text">Live sessions</p>
</div>
</div>
</li>
<li class="cards_item">
<div class="card">
<div class="card_image"><img src="https://via.placeholder.com/50"></div>
<div class="card_content">
<p class="card_text">Job Assistance</p>
</div>
</div>
</li>
</ul>
</div>
2
Answers
try adding z-index on ribbon, like this:
Your list markup is invalid. A div is not a valid child of a list element. Fortunately we don’t want it in the list anyway. We’ll position it absolutely inside a shared container (which needs relative positioning to contain the ribbon). We can center it with the usual 50% tricks.
Also, you don’t need vendor prefixes for transform. See https://caniuse.com/transforms2d.