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

How do I center the login information in the middle of this login box?

I’m testing some scenarios with flexbox while learning HTML and CSS. I can’t for the life of me get the user-input div centered in the middle of the login-box div. I was able to get it centered vertically with align-items: center; but I can’t get it to move down without using margins (which I would prefer to avoid).

HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>
            Login
        </title>
        <link rel="stylesheet" href="styles.css">
    </head>
    <body>
        <div class="page-container">
            <div class="login-box">
                <div class="user-input">
                    <input class="email" type="text" placeholder="Email">
                    <input class="password" type="text" placeholder="Password">
                    <button class="login-button">Login</button>
                </div>
            </div>
        </div>
    </body>
</html>

CSS:

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

.page-container {
    display: flex;
    height: 100vh;
    justify-content: center;
    align-items: center;
}

.login-box {
    height: 350px;
    width: 250px;
    box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.41);
    border-radius: 10px;
}

.user-input {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.email,
.password {
    width: 150px;
    border-radius: 5px;
    border: .5px solid black;
}

.login-button {
    height: 25px;
    width: 100px;
    border: none;
    background-color: darkblue;
    color: white;
    border-radius: 5px;
    margin-top: 10px;
    cursor: pointer;
}

The login-box div is the rectangular shadow box in the middle of the screen. The user-input is where I have a column flexbox created.

Here's a screenshot.

>Solution :

change .login box styling:

.page-container {
        display: flex;
        height: 100vh;
        justify-content: center;
        align-items: center;
    }

    .login-box {
        height: 350px;
        width: 250px;
        box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.41);
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .user-input {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .email,
    .password {
        width: 150px;
        border-radius: 5px;
        border: .5px solid black;
    }

    .login-button {
        height: 25px;
        width: 100px;
        border: none;
        background-color: darkblue;
        color: white;
        border-radius: 5px;
        margin-top: 10px;
        cursor: pointer;
    }
<!DOCTYPE html>
<html>

<head>
    <title>
        Login
    </title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="page-container">
        <div class="login-box">
            <div class="user-input">
                <input class="email" type="text" placeholder="Email">
                <input class="password" type="text" placeholder="Password">
                <button class="login-button">Login</button>
            </div>
        </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