The alignment and height of a Bootstrap col-auto layout gets disrupted when a button component is removed

Looking for assistance in achieving a flex column layout with Bootstrap, where the header and footer areas adjust their height automatically while the content area remains scrollable. The issue arises when hiding or removing the "previous button" from the footer with the col-auto class, causing a break in height alignment. Any solutions?

setTimeout(() => {
  document.querySelector('.prev-btn').remove();
}, 2000);
html,
body {
  height: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2909d9d868186809382b2c7dcc0dcc1">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />

<div class="container-fluid p-0 h-100">
  <div class="row g-0 flex-column h-100">
    <header class="col-auto bg-secondary">
      <nav class="navbar bg-light">
        <div class="container-fluid">
          <a class="navbar-brand">Navbar</a>
          <form class="d-flex" role="search">
            <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success" type="submit">Search</button>
          </form>
        </div>
      </nav>
    </header>

    <div class="col d-flex align-items-center justify-content-center overflow-auto">
      <div class="col-6 py-3 m-auto">
        Content area
      </div>
    </div>

    <footer class="col-auto">
      <div class="container-fluid p-3 bg-light">
        <div class="row g-0 align-items-center">
          <div class="col">
            <button class="btn fw-bold btn-outline-danger shadow-none">CANCEL &amp; RESTART</button>
          </div>
          
          <div class="col-auto px-3 text-center">STEP 1 OF 4</div>
          
          <div class="col">
            <div class="d-flex justify-content-end">
              <button class="btn fw-bold btn-outline-primary px-5 shadow-none">NEXT</button>
            </div>
          </div>
        </div>
      </div>
    </footer>
  </div>
</div>

Answer №1

It appears that the issue is due to the CANCEL & RESTART button wrapping during reflow. To address this, you can utilize Bootstrap's text-nowrap class to prevent it, although this may necessitate other layout adjustments for smaller screens. An alternative solution could be relocating the "1 of 4" label above the buttons for mobile view.

setTimeout(() => {
  document.querySelector('.prev-btn').remove();
}, 2000);
html,
body {
  height: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32505d5d46414640534272071c">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />

<div class="container-fluid p-0 h-100">
  <div class="row g-0 flex-column h-100">
    <header class="col-auto bg-secondary">
      <nav class="navbar bg-light">
        <div class="container-fluid">
          <a class="navbar-brand">Navbar</a>
          <form class="d-flex" role="search">
            <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success" type="submit">Search</button>
          </form>
        </div>
      </nav>
    </header>

    <div class="col d-flex align-items-center justify-content-center overflow-auto">
      <div class="col-6 py-3 m-auto">
        Content area
      </div>
    </div>

    <footer class="col-auto">
      <div class="container-fluid p-3 bg-light">
        <div class="row g-0 align-items-center">
          <div class="col">
            <button class="btn fw-bold btn-outline-danger shadow-none text-nowrap">CANCEL &amp; RESTART</button>
          </div>
          
          <div class="col-auto px-3 text-center">STEP 1 OF 4</div>
          
          <div class="col">
            <div class="d-flex justify-content-end">
              <button class="btn fw-bold btn-outline-secondary px-5 me-3 shadow-none prev-btn">PREVIOUS</button>
              <button class="btn fw-bold btn-outline-primary px-5 shadow-none">NEXT</button>
            </div>
          </div>
        </div>
      </div>
    </footer>
  </div>
</div>

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

Tips for showcasing personalized validation alerts with jQuery in the HTML5 format?

One of the Javascript functions I designed is for validating file extensions before uploading: function validateFileExtension(field, extensions){ file_extension = field.val().split('.').pop().toLowerCase(); if ($.inArray(file_extension,exten ...

Optimal method for utilizing Babel to generate a unified JavaScript bundle

I have multiple JS files and I need to combine them into a single JS bundle using Babel. Someone pointed me towards this first resource, but I am having trouble grasping the instructions: https://babeljs.io/docs/usage/cli/ While searching online, I came ...

Adding a CSS link to the header using JavaScript/jQuery

Is there a way to dynamically inject a CSS link located in the middle of an HTML page into the head using JavaScript? <head> ... styles here </head> <body> code <link href='http://fonts.googleapis.com/css?family=Lato:400,300, ...

Issue with Datepicker functionality within the <th> element is causing it to malfunction

Currently, I am attempting to utilize the Bootstrap datepicker, but I am facing an issue when trying to implement it within a table, specifically inside a th element. Below is the structure of my table: <table id="table" class="table table-bord ...

AngularJS Application experiencing extremely slow performance with IE's "Style Calculation" feature

In my AngularJS app, I am using Angular Material and loading data from an external API. Everything runs smoothly in Chrome, Firefox, and Safari, but when it comes to Internet Explorer, the performance is abysmal. The app becomes slow, CSS animations are c ...

What is the method for adjusting the size of text while rendering on a canvas?

When it comes to scaling text with CSS transform scale, for instance: transform: scale(2, 4); fontSize: 20px // Is including fontSize necessary? I also have the task of displaying the same text on a canvas element. function draw() { const ctx = document ...

Steps for retrieving the currently selected text inside a scrolled DIV

An imperfect DIV with text that requires a scroll bar For example: <div id="text" style='overflow:scroll;width:200px;height:200px'> <div style='font-size:64px;'>BIG TEXT</div> Lorem Ipsum is simply dummy text of th ...

Avoid blurry CSS zoom by opting for pixelated images instead

Is there a way to use the zoom property in CSS for images without creating a blurry effect when enlarging them, but instead make them pixelated? How can I accomplish this? Edit: If needed, I am open to utilizing different properties or languages. ...

The autocomplete feature in Google Maps is not functioning properly when used within a modal

I've integrated the Google Maps API to enable autocomplete address functionality for an input box on my page. However, I'm encountering an issue where everything works fine on the page itself, but it doesn't work when the input box is placed ...

Execute scroll to top animation but without utilizing $('html,body').animate({scrollTop: 0}, 'slow')

As someone who is just starting to explore jQuery, I hope you can bear with me. I've implemented this styling: html, body{ height: 100%; overflow: auto; } Along with this script: $(document).ready(function() { $('#guide-wrap'). ...

Using inline CSS to apply conditional styles to a component in React is a great way to customize the

I'm currently working on customizing the styles of some buttons depending on their 'active' status and whether the user is hovering over them. So far, it's partially working but I'm encountering behavior that I can't fully com ...

Inspecting the options within a dropdown menu to adjust a styling attribute

I am in the process of developing a website that features multiple select options for creating sentences. My goal is to detect when users are changing these options to form specific sentences, such as changing "I", "Am", "Blue" to reflect the color blue. T ...

I'm wondering, what is the name of this, and how can I recreate it using CSS?

Apologies for the lackluster title, but I'm completely stumped on what to name my creation. I'm looking to put together a list of links (or a menu, without any drop-downs) that has a unique appearance: This example isn't the most attractiv ...

Click to activate the Selectfield option

There are 3 links that populate the select field with various options. When the text label is active and someone clicks on the link selectlist1 or another, it should activate the select label. How can this be achieved? <!doctype html> <html> ...

Automatic display of jquery datepicker in modal dialog is a convenient feature

After finally getting the datepicker to function in my modal dialog, I encountered an issue where it doesn't open automatically the first time I click on it (as expected). However, when I close the dialog and reopen it, the datepicker pops up automati ...

Achieve a left-aligned text section that remains centered using Bootstrap 4

I encountered a problem with bootstrap-4. I tried centering a section using the text-center class: <div class="text-center text-left"> <h2>Hi,I'm,</h2> <h2>Bonheur jed,</h2> <h2>Web Developer.</h2&g ...

Present user-generated incorrect HTML content without disrupting the webpage layout

My website offers users the ability to input and save text content, which can then be displayed as desired. Users have the freedom to utilize HTML tags for formatting purposes such as design, fonts, divs, tables, and more... However, when it comes to disp ...

Perform Jquery trigger on mobile by clicking, and on desktop by hovering

Despite encountering this question numerous times, I am still unable to find a solution. I have a dropdown menu and I want it to open on hover for desktop and on click for mobile devices. I attempted using the provided code, however, it only works after r ...

Show off the images once they have finished loading completely?

Is there a way to ensure that the image is shown on the webpage only once it has been completely loaded? <ul id="listcontainer"> <li class="li1"> <img src="images/m1.png"> </li> </ul> ...

Adjust the background color of a column in HTML based on its corresponding color name

Is there a way to change the background color of a column in an HTML table if the value is green? We want the background color to reflect the color name. The data will be retrieved from a web service. Here is the HTML code used to display the data in the ...