Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

top, bottom, right, left values not working as flex container is set as justify-content: center

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading