What is the method for stretching the navbar and content to fill the entire viewport in Bootstrap?

Can anyone help me with an issue regarding a navigation bar and content created in Bootstrap 5? I'm trying to use vh-100 to make both the navigation bar and content stay on the view page without a scrollbar. However, the size of the navigation bar is causing the content to be pushed below it. How can I ensure that both elements remain visible even when zoomed in?

This is what I've tried so far:

https://jsfiddle.net/daxejno5/

.bg-darkblue{
    background-color: #ccc;
}

#test{
    overflow-y: scroll;
    overflow-x: hidden;
}
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
      <link rel="stylesheet" type="text/css" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fbf6f6edeaedebf8e9d9acb7a8b7aa">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-light p-0 bg-darkblue">
    <div class="container-fluid">
        <a class="navbar-brand text-light" href="/">Test</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarText">
            <ul class="navbar-nav ms-auto mb-2 mb-lg-0">

            </ul>
        </div>
    </div>
</nav>
    
<div class="col-sm-9 p-0">
    <div class="card rounded-0 vh-100">
        <div id="test" class="card-body p-0 d-flex flex-column-reverse">
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Voluptatum ipsum vero saepe accusamus magnam nemo consectetur voluptas quidem similique mollitia repudiandae quam voluptatibus, maiores hic! Rerum unde consequatur a aliquid.
            <!-- more lorem ipsum content -->
        </div>
        <div class="card-footer text-muted">
            <form id="test-form" class="m-0">
                <div class="row">
                    <div class="col">
                        <input type="text" class="form-control rounded-pill" autocomplete="off" placeholder="Type something...">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- closing body and html tags -->

https://i.sstatic.net/ykYEH.png

Answer №1

Utilizing a mix of flex utilities, viewport sizing, and overflow appears to be effective in this scenario. I've repositioned the footer outside the content element as a sibling to the header and content.

.bg-darkblue {
  background-color: darkblue;
}
<head>
  <link rel="stylesheet" type="text/css" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04666b6b70777076657444312a352a37">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>

<body>
  <div class="d-flex flex-column vh-100">
    <nav class="navbar navbar-expand-lg navbar-dark p-0 bg-darkblue">
      <div class="container-fluid">
        <a class="navbar-brand text-light" href="/">Test</a>

        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
      </button>

        <div class="collapse navbar-collapse" id="navbarText">
          <ul class="navbar-nav ms-auto mb-2 mb-lg-0"> </ul>
        </div>
      </div>
    </nav>

    <div class="flex-fill overflow-auto">
      <div class="card rounded-0">
        <div id="test" class="card-body p-0 d-flex flex-column-reverse">
          "Lorem ipsum dolor sit amet consectetur, adipisicing elit..."
        </div>
      </div>
    </div>

    <div class="card-footer text-muted">
      <form id="test-form" class="m-0">
        <div class="row">
          <div class="col">
            <input type="text" class="form-control rounded-pill" autocomplete="off" placeholder="Type something...">
          </div>
        </div>
      </form>
    </div>
  </div>
</body>

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

Is it possible to adjust the color of this AnchorLink as I scroll down?

Currently struggling to update the color of a logo as I scroll. While the navigation bar successfully changes colors, the logo remains stagnant. Here is the excerpt from my existing code: navigation.js return ( <Nav {...this.props} scrolled={this ...

Button for Toggling Audio Play and Pause

Is it possible to create an SVG image that changes color slightly when hovered over, and when clicked toggles to another SVG image that can be switched back to the original by clicking again with the same hover effect? Additionally, when clicked, it should ...

In what format is the parameter accepted by the .getDay() method?

Here's the plan: I need to extract information from an input element with type set as date. This data will then be stored in a .json file and later parsed when the program is initiated. Subsequently, I aim to utilize the date.getDay() function to dete ...

Issue with embedding icon within input field in Bootstrap version 4.1

I am currently implementing a project using Angular 6 along with the latest version of Bootstrap v4.1. I am attempting to create a reactive form with icons within input fields. As there is no direct way in bootstrap to place icons on the left side of input ...

Change the opacity of a DIV or any other element when hovering over it

I have successfully applied opacity: 1; to a paragraph when hovering over itself. However, I want the opacity to also change when hovering over the header above it. Here is my CSS code: .testH { font-family: impact; text-align: center; font-s ...

I struggled to insert a horizontal scrollbar into the iframe

In the process of constructing a family tree, I am utilizing lists as elements to create the structure. However, I am encountering an issue when the tree grows larger - no horizontal scrollbar is appearing. I have attempted to use iframe and CSS to manage ...

The visibility of the eye icon on the password field may vary, occasionally appearing and disappearing from view

Here is the code for my login form password field (I'm using bootstrap 4): <div class="form-account-label-input"> <label> Password <span class="star-red">&nbsp;*</span></label> <input type ...

Tips on preventing form submission when clicking on another button within the same form

I created a shopping cart page with functionality to adjust the quantity using JavaScript. I have shared some of the HTML code below, <form action="payment.php" method="post"> <div class="qty__amount"> ...

Using jQuery to show and hide elements on a webpage

One issue I'm facing is changing the content on a page depending on the clicked link. The problem arises when the displayed content for one link persists even after clicking another link, despite setting it to not display when another link is clicked. ...

Triggering a JQuery event to switch between tabs

Currently, I am in the process of developing a web application that incorporates nav-tabs from Bootstrap. These nav-tabs consist of 4 different tab-contents. My main concern lies in determining which nav-tab the user has selected among the 4 tabs and updat ...

Compilation of CSS by Webpack resulting in peculiar class identifiers

Currently, I am using webpack for developing a React app with a NodeJS backend. I've encountered an issue with styling the app as webpack seems to be interfering with my CSS, causing changes in class names. For example, in my base.css file, I have d ...

Which selector in CSS is applicable for targeting Bootstrap tooltips?

After some experimentation, I've mastered the functionality of Twitter Bootstrap Tooltips and am now focused on customizing their appearance. Previous inquiries into other plugins revealed specific CSS selectors - for example, jScrollPane had a track ...

The public folder in Node.js is known for its tendency to encounter errors

I'm facing an issue with displaying an icon on my website. Here is the current setup in my code: app.js const http = require('http'); const fs = require('fs'); const express = require('express') const path = require(&apo ...

How about implementing built-in validation for Vue Headless UI Listbox (Select) element?

I need assistance in integrating native validation support into the Vue3 or Nuxt 3 Vue Headless UI Listbox (Select) component. It appears that direct support is not available, so I am looking for the best and most straightforward approach to achieve this. ...

Flexible design for your website content wrapper

When I display the content on my website, it sometimes overlaps the footer because the wrapper does not adjust its size based on the content. I set the height to an absolute value and now I need to find a more flexible option to prevent this issue. I' ...

Guide to changing an image on a canvas with KineticJS

I am currently working on developing a canvas that will display a hotel floor view. I have images stored in a database which I am drawing onto the canvas using x and y coordinates from the database as reference points. However, I want to add touch events t ...

What is causing the QJsonValue(undefined) to be returned?

After sending a request to the API for bid price, I am receiving an undefined QJsonValue and unable to display it later. Can anyone help me pinpoint where I might be going wrong? { QApplication a(argc, argv); MainWindow w; w.show(); QNetwor ...

Customize the Bootstrap Navbar to display background only on the right side and not across the entire width

I am utilizing Bootstrap's navbar, specifically using the dropdown toggler icon on the right side. I am looking to have a background that only covers the right portion of the width and not the entire width. Any suggestions or insights would be greatly ...

Leveraging Angular for REST API Calls with Ajax

app.controller('AjaxController', function ($scope,$http){ $http.get('mc/rest/candidate/pddninc/list',{ params: { callback:'JSON_CALLBACK' } }). success(function (data, status, headers, config){ if(ang ...

Leveraging BeautifulSoup for extracting information from HTML documents

I'm working on a project to calculate the distance between Voyager 1 and Earth. NASA has detailed information available on their website at this link: ... I've been struggling to access the data within the specified div element. Here's the c ...