HTML

<body>
    <div class="parent">
        <div class="child"></div>
    </div>
</body>

Method #1

.parent{
    background-color: red;
    height: 300px;
    width: 300px;
    margin: 0 auto;
}

Method #2

.parent{
    background-color: red;
    height: 100vh;
    width: 300wh;
    display: flex;
    justify-content: center;
    align-items: center;
}
.child{
    background-color: blue;
    height: 300px;
    width: 300px;
}

Method #3

.parent{
    background-color: red;
    height: 100vh;
    width: 300wh;
    display: grid;
    place-items: center;
}
.child{
    background-color: blue;
    height: 300px;
    width: 300px;
}

Method #4

.parent{
    background-color: red;
    height: 100vh;
    width: 300wh;
}
.child{
    background-color: blue;
    height: 300px;
    width: 300px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.