I want to make a tag for a card on my website for a new product. My idea is to have something like this
in the top left corner of the card.
I am writing about this, because I need help making the css for it.
I tried making it just a square with rounded corners, but I didn’t like the look. Here is the example of the layout.
Here is the html and css for the card:
CSS
#games div {
background-color: #3A7BCD;
border-radius: 7px;
cursor: pointer;
overflow: clip;
min-width: 100%;
max-width: 400px;
margin-bottom: 15px;
}
#games div *:not(img) {
margin: 10px;
}
#games div img {
width: 100%;
height: 200px;
object-fit: cover;
}
HTML
<div>
<img src="https://i.postimg.cc/9FJYqQKg/Screen-Shot-2024-05-08-at-4-22-24-PM.png" alt="Banner image">
<h2>
Title
</h2>
<p>
Description
</p>
</div>
2
Answers
Your problem is in the overflow property defined as clip, in this case in practice you are hiding all the content that overflows your element. A possible solution (although it may not be ideal) would be to wrap your element in a div with the same dimensions and then add the tag you want.
Have a look at this example, where I used a simple div instead of an image: It has
position: absolute
, the parent hasposition: relative
to act as the position root. Theleft
andtop
parameters can be adjusted as needed, as well as thetransform: rotate(...)
angle. But the principle should be clear: