Exploring the power of Bootstrap 5 for vertical alignment

I am currently utilizing the flexbox grid from Bootstrap 5 to create a mobile-first Angular web application that is responsive.

For the home screen of my app, I want to incorporate these 3 elements :

  1. The title of the app displayed at the top
  2. A series of buttons positioned in the center of the screen
  3. A footer placed at the bottom of the screen

What is the optimal responsive approach to align these elements at the top, middle, and bottom of the screen respectively, while also keeping them centered horizontally?

My code currently appears like this :

<div class="container-fluid">
<div class="row">
    <div class="col-12 d-flex justify-content-center">
        <h1>App name</h1>
    </div>
</div>
<div class="row">
    <div class="col-12 col-sm-6 col-lg-3 d-flex">
        <button type="button" class="btn btn-outline-primary flex-fill">First button</button>
    </div>
    <div class="col-12 col-sm-6 col-lg-3 d-flex">
        <button type="button" class="btn btn-outline-primary flex-fill">Second button</button>
    </div>
    <div class="col-12 col-sm-6 col-lg-3 d-flex">
        <button type="button" class="btn btn-outline-primary flex-fill">Third button</button>
    </div>
    <div class="col-12 col-sm-6 col-lg-3 d-flex">
        <button type="button" class="btn btn-outline-primary flex-fill">Fourth button</button>
    </div>
</div>
<div class="row">
    <div class="col-12 d-flex justify-content-center">
        <p>Footer</p>
    </div>
</div>

Many thanks!

Answer №1

To achieve vertical alignment in Bootstrap using flexbox, you can make use of auto-margins within the flex container. This allows for easy centering and alignment of elements.

<div class="container-fluid vh-100 d-flex flex-column">
    <div class="row">
        <div class="col-12 d-flex justify-content-center">
            <h1>App name</h1>
        </div>
    </div>
    <div class="row my-auto">
        <div class="col-12 col-sm-6 col-lg-3 d-flex">
            <button type="button" class="btn btn-outline-primary flex-fill">First button</button>
        </div>
        <div class="col-12 col-sm-6 col-lg-3 d-flex">
            <button type="button" class="btn btn-outline-primary flex-fill">Second button</button>
        </div>
        <div class="col-12 col-sm-6 col-lg-3 d-flex">
            <button type="button" class="btn btn-outline-primary flex-fill">Third button</button>
        </div>
        <div class="col-12 col-sm-6 col-lg-3 d-flex">
            <button type="button" class="btn btn-outline-primary flex-fill">Fourth button</button>
        </div>
    </div>
    <div class="row">
        <div class="col-12 d-flex justify-content-center">
            <p>Footer</p>
        </div>
    </div>
</div>

Check out the demo here

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

"Struggling to position the bottom navbar at the center in Bootstrap?

Can someone help me center the icons in my second navigation bar? I've tried aligning them left and right, and that works, but when I try to center them, it doesn't work at all. Did I miss something in the code or make a mistake? Any assistance w ...

Stop div from exceeding the page boundaries

Here's my current dilemma: I have a simple css3 tooltip-menu that is hidden by default and appears on mouseover. It has a fixed width and is positioned absolutely to the right (with an arrow in the middle pointing to the hovered element). The issue I ...

Develop a website using HTML and CSS for the front-end design, complemented by Java for the

I find myself at a standstill with a project I want to tackle, but unfortunately, my knowledge of modern web development, particularly full stack, is minimal. As a result, I am completely clueless on how to proceed. Here is what I am familiar with and what ...

To optimize your bundling process, include the leaflet.css file from the node_modules/leaflet directory using webpack

Currently, I am working on developing a map application using webpack and leaflet. While I can successfully require leaflet.js from my map.js file, I encounter an error when trying to call leaflet.css. The configuration in my webpack.config.js is as follo ...

Seamless Navigation with Bootstrap Navbar and SmoothScroll

Currently, I have a custom-built navbar that functions perfectly, with full mobile responsiveness. However, I am facing an issue with the nav-item's (headings). The nav-item's direct users to different sections of the same page using #. I have i ...

Having difficulty retrieving an angular file from a location outside of the asset folder

I'm encountering issues with a small project that is meant to read a log and present it in table format. Here is the outline of the project structure: project structure Within the LOG directory, I should be able to access motore.log from my DataServi ...

The background color of the HTML element is not displaying properly in Internet Explorer 8

Currently, I am using the <body> tag to wrap three divs on a website where all background colors are set to white. In the CSS, I have specified the background color as #fff for the html and body tags. The site displays correctly in every browser exc ...

Can a fixed div be made to adapt to different screen sizes?

Struggling to make SVG data charts responsive due to the 'position:fixed' CSS attribute applied, I'm exploring alternative solutions that don't involve media queries. Ideally, I want the SVG to scale up and down while remaining centered ...

Determine whether to show or hide a div based on the width of the

Is there a way to dynamically hide a div using Bootstrap 4 based on the screen width? Can this be achieved without using JavaScript? I am particularly interested in hiding certain text elements that are not relevant on smaller screens, such as mobile de ...

What is the best approach for promoting reusability in Angular: creating a new CSS class or a new component?

I have a div with a set of CSS properties that are essential to my application. These properties will be reused across multiple pages and components. <div style="display: flex; flex-direction: column; height: 100%"> //inner html will vary based on c ...

Can you identify the specific name of the IE CSS bug affecting double vertical padding?

(Just when I thought I've encountered all the strange IE CSS bugs, here comes another one. Is there a name for this double-vertical-padding bug?) After creating a simple test case that worked perfectly in browsers like FF and Opera, I was surprised t ...

SASS causing conflicts with CSS breakpoints selector overrides

I am working with a partial file named _display.scss. It includes various @mixin and styling classes related to the display CSS property. _display.scss @mixin d-block{ display: block; } @mixin d-none{ display: none; } .d-block{ @include d- ...

Changing the color of a pressed Bootstrap 4 button

After making changes to the bootstrap css class of the button such as the color, font size, and font color, I noticed that when I click and hold the mouse on the button, the color changes. Even though I set the color to green, when I click and hold the mo ...

What causes the card to exceed the boundaries of its parent column?

My Form elements seem to be misaligned and not fitting correctly. .h-100 is used for the blue navigation background to occupy the full height of the screen. An answer explaining why my code snippet is not working would be appreciated. View Plunker here ...

Get both div tags within a single find_all function call in Beautiful Soup

Is there a way to extract multiple HTML div tags using a single "soup.find_all" function in beautifulSoup? The divs are labeled as "event odd" and "event even" on the webpage, and I want to iterate through all of them. Here is an example of the webpage co ...

$PHP_SELF will be executed immediately upon the page loading

I recently designed an HTML page for inputting data into a MySQL database. In this setup, I've integrated PHP scripting directly within the HTML code. Take a look at the snippet below, <html> <head> </head> <body> <?php / ...

The elements of the second flex item should also be arranged in a line next to each other

<script src="https://use.fontawesome.com/2a2c577e07.js"></script> <div class="parent-flex"> <div class="class1">Class 1</div> <div class="class2"> <img src="http://farm4.static.flickr.com/3140/3506456511_43787 ...

Unable to retrieve the desired dropdown element using xpath location strategy

On my website, I have a drop-down menu for selecting time zones and I need to be able to access the options easily. https://i.sstatic.net/jR4gx.png Here is the HTML code snippet: <li> <div id="ember2503" class= ...

I am attempting to change a "+" symbol to a "-" symbol using a Bootstrap toggle feature

Click on the text to reveal more information that drops down below. I am using Bootstrap icons and attempting to show a "+" icon when the toggle is collapsed, and a "-" icon when it's open. I've been trying to use display properties, but haven&ap ...

Display a specific element only if another element exceeds a specified height

A snippet of HTML code is given below: <span class="day-number">{{day-number}}</span> <div class="event-box"> <div class="event-container"> </div> <div class="more-events">more ...</div> </div> The .e ...