All elements align in the same row after using flexbox

Viewed 48

I am making a simple counter program. After putting the label and the buttons in a div container and using flexbox on them, the buttons and the label aligned in the same line even though I used display block on the label and applied a br tag after it. I want the buttons below the number label.

Here is my code -:

For HTML -:

<!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">
    <title>Counter</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <label id="countLabel">0</label>
        <br>
        <div class="btns">
            <button id="decrease">Decrease</button>
            <button id="reset">Reset</button>
            <button id="increase">Increase</button>
        </div>
    </div>
    <script src="index.js"></script>
</body>
</html>

For CSS -:

#countLabel{
    display:inline-block;
    text-align: center;
    font-size: 70px;
}
.container{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
}
.btns{
    display:flex;
    justify-content: center;
}
#decrease{
    margin:20px;
    padding:10px;
    font-family: 'Georgia';
    font-size: 20px;
    font-weight: bold;
    background-color: rgb(245, 112, 72);
    border:2px solid orange;
    border-radius: 10px;
    color:rgb(0, 0, 0);
}
#reset{
    margin:20px;
    padding:10px;
    font-family: 'Georgia';
    font-size: 20px;
    font-weight: bold;
    background-color: rgb(179, 167, 164);
    border:2px solid rgb(70, 69, 69);
    border-radius: 10px;
    color:rgb(0, 0, 0);
}
#increase{
    margin:20px;
    padding:10px;
    font-family: 'Georgia';
    font-size: 20px;
    font-weight: bold;
    background-color: rgb(149, 241, 87);
    border:2px solid rgb(1, 170, 15);
    border-radius: 10px;
    color:rgb(0, 0, 0);
}

Here is the result -:

Image

Any help would be great.

Thank You.

1 Answers

Try this:

body{
    margin: 0;
}
#countLabel{
    display:inline-block;
    text-align: center;
    font-size: 70px;
}
.full_page{
    height: 100vh;
    display: flex;
    align-items: center;
}
.container{
    display: flex;
    justify-content: center;
    align-items: baseline;
    width: 100vw;
}
.btns{
    display:flex;
    justify-content: center;
}
#decrease{
    margin:20px;
    padding:10px;
    font-family: 'Georgia';
    font-size: 20px;
    font-weight: bold;
    background-color: rgb(245, 112, 72);
    border:2px solid orange;
    border-radius: 10px;
    color:rgb(0, 0, 0);
}
#reset{
    margin:20px;
    padding:10px;
    font-family: 'Georgia';
    font-size: 20px;
    font-weight: bold;
    background-color: rgb(179, 167, 164);
    border:2px solid rgb(70, 69, 69);
    border-radius: 10px;
    color:rgb(0, 0, 0);
}

.label_container {
    text-align: center;
}

#increase{
    margin:20px;
    padding:10px;
    font-family: 'Georgia';
    font-size: 20px;
    font-weight: bold;
    background-color: rgb(149, 241, 87);
    border:2px solid rgb(1, 170, 15);
    border-radius: 10px;
    color:rgb(0, 0, 0);
}
<!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">
    <title>Counter</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="full_page">
   <div class="inner_full_page">    
    <div class="label_container">
        <label id="countLabel">0</label>
    </div>
    <div class="container">
        <div class="btns">
            <button id="decrease">Decrease</button>
            <button id="reset">Reset</button>
            <button id="increase">Increase</button>
        </div>
    </div>
   </div>
  </div>
    <script src="index.js"></script>
</body>
</html>

Related