Flexbox allows all elements to fall in line in a single row

I'm trying to create a basic counter program. I have placed the label and buttons inside a div container and used flexbox styling on them. However, despite setting the display of the label to block and adding a line break after it, the buttons and label still appear on the same line. I actually want the buttons to be positioned below the number label.

Below is the code snippet:

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>

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);
}

Check out the output here -:

https://i.sstatic.net/1UG6D.png

Your assistance is highly appreciated.

Thanks!

Answer №1

Here is a suggestion:

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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Activate navigation state dynamically

Having encountered this issue repeatedly, I struggle to find a solution. My Wordpress site features a top navigation located in my header.php file and used across all pages, making it impossible to hardcode the active menu state for each individual page. ...

Hide a div element upon selecting an option from a dropdown menu

On iPhone 6plus and lower, I created a dropdown menu that opens when users click on "jobs" or "contact." However, after clicking on these options, the drop-down menu remains open. How can I make it hide automatically after a list item is clicked at this sp ...

In IOS 9.0, flex items do not wrap to new lines and result in overflow

While it functions properly in other browsers, the issue arises in Safari. I require the flex items to occupy the entire width on screens smaller than 768px. Currently, they are taking up the full width of their container but remaining in a single line, wh ...

How to Remove a CSS Class from an <li> Tag in ASP.net Using Code Behind

Currently, I am adding a CSS class to my li tag using the following code snippet: liComPapers.Attributes.Add("class", "NoDisplay"); Is there a way to remove this specific class (NoDisplay) from the li tag at a different location in my code? I have attem ...

Struggling to remove the excess white space while working with Bootstrap 5

Trying to eliminate the white space visible in the image. Utilizing Bootstrap for my project, but still getting acquainted with it. My teacher suggested (without reviewing any code) that a container might be causing the issue. I disagree as the HTML contai ...

Ways to enable file/result downloads on a website using HTML

Could you please take a look at this repository: https://github.com/imsikka/ArtGallery I am looking to create a downloadable result using a download button. I can create the button, but I am unsure of how to make the file actually downloadable. Do I need ...

What is the best way to showcase a half star rating in my custom angular star rating example?

component.ts import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { projectRating ...

Can JavaScript be utilized to randomly generate a predetermined link color and hover color each time the page is refreshed?

I have never ventured into the world of javascript before, but I am curious to find out if it is feasible to achieve what I have in mind before investing time in learning the language. After spending a few days browsing forums and experimenting with code ...

How are these background images able to remain in a fixed position like this?

Trying to name this question correctly was a bit tricky. Hopefully I got it right. I have a new client and they want their website to have a similar feel to . If you check out the index page and scroll down, there's this cool 'smooth animation& ...

Footer Troubles on Internet Explorer 11

I am experiencing an issue with the layout in Mozilla and IE 11. The content inside the Div is appearing below the footer, as shown in the screenshot provided. Below you can find the code for the div and the footer sections. The Div is enclosed within a se ...

Header bar not extending across the entire width of the screen when viewed on mobile devices

View the problem screenshot hereWelcome to my first stackoverflow post, please be gentle if I make any mistakes. I'm currently working on a project for a course using Bootstrap 4. The issue I'm facing pertains to the navbar losing its full width ...

Issue with Bootstrap 3 navbar dropdown menu persisting when clicking outside of it

My website has a navbar with a single dropdown menu positioned on the right-hand side. However, I am facing an issue when using it on mobile devices - when I click the toggle button (3 bars), the menu is displayed but the icon disappears. The problem esca ...

Ways to centrally align the bootstrap modal vertically

As a newcomer, I have exhausted all available solutions before turning to this platform for help. Here is my current CSS code: #orphanModal{ .modal-body{ min-height: 450px; margin-bottom: 10px; } .modal-footer { margin: 0; padding: ...

Innovative: Enhancing column width dynamically without compromising grid integrity

Currently, I am utilizing Bourbon's Neat library to structure my grid system. Within my code, I have the following setup: section { @include outer-container; aside { @include span-columns(3); } article { @include span-columns(9); } } The chal ...

Change the button icon to something new when you hover over it

Below is the liquid code I am working with: <a href="{{ section.settings.button_link }}" class="btn--rounded"> {% include 'icon-btn--rounded' %} <div class="link-label">{{ section.settings.button_ ...

What is the best way to increase the spacing between images in a navbar?

Having trouble aligning images in navbar with bootstrap. Tried various solutions without success. Here is my code snippet and image of my current page: <body> <header id="header" class="fixed-top"> <nav class=" ...

Can I centralize the styling and JavaScript references for use across all pages of an HTML website?

I currently have more than 50 HTML pages where I include style, JavaScript, and Bootstrap references on each one. Changing the style path on all of these pages can be a time-consuming task. Is there a way to define my styles, JavaScript, and Bootstrap in ...

Instructions for creating scrollable MaterializeCSS tabs when there are too many tabs to fit within the width of the container without scrolling

Here is an example code (SSCCE) that showcases the issue I am facing. The MaterializeCSS frontend framework documentation states: Scrollable Tabs Tabs automatically become scrollable Source However, when I attempt to use more tabs than can fit on the ...

The image on my background is getting distorted on Chrome

When using Chrome 27 on a Windows 7 ASUS UX31 laptop (also tested on a MacBook Pro), I encounter an issue on my website, . After scrolling down and back up, I notice that the background image on the carousel is half missing. The problem persists even after ...

What is the best way to include two class names within a single div using Next.js?

Struggling to include two different CSS classes into a single div element, I encountered some issues. For reference, here is a screenshot: https://i.stack.imgur.com/UuCBV.png https://i.stack.imgur.com/sHNwq.png My code snippet looks like this: blog.js ...