Im trying to make the ‘rating-block’ to be positioned at the bottom-right side of ‘card’. But these values don’t work as its container has justify-content centre so it will force it in the centre. Is there a better way to position it to the bottom right?
.card {
width: 210px;
height: 250px;
display: flex;
align-items: center;
justify-content: center;
background-color: green;
position: relative
}
.card-img {
display: flex;
width: 50%;
}
.rating-block {
background-color: white;
border-radius: 10px;
position: absolute;
padding: 0 10px;
top: 100px;
}
.rating {
margin: 0px
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="card">
<img src="https://m.media-amazon.com/images/I/41rsAHrKw1L._AC_SY580_.jpg" alt="card-1" class="card-img">
<div class="rating-block">
<p class="rating">4.5</p>
</div>
</div>
</body>
</html>
>Solution :
Try adding top: 185px; and left: 115px; to the .rating-block class
.card {
width: 210px;
height: 250px;
display: flex;
align-items: center;
justify-content: center;
background-color: green;
position: relative
}
.card-img {
display: flex;
width: 50%;
}
.rating-block {
background-color: white;
border-radius: 10px;
position: absolute;
padding: 0 10px;
top: 185px;
left: 115px;
}
.rating {
margin: 0px
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="card">
<img src="https://m.media-amazon.com/images/I/41rsAHrKw1L._AC_SY580_.jpg" alt="card-1" class="card-img">
<div class="rating-block">
<p class="rating">4.5</p>
</div>
</div>
</body>
</html>