Unable to adjust the main-container height in Bootstrap to 100%

I'm struggling to set the height of my .main-container to 100%.

When I try to do that, the height ends up being too high. Here is a screenshot for reference: enter image description here

.main-container {
    height: 94vh;
}

Here is some of my code where I'm using Bootstrap 5:

<nav class="navbar fixed-top custom-navbar">

To position my sidebar and main page, I am using the following code:

<div class="main-container d-flex">
    <div id="side_nav">...</div>
    <div class="content">...</div>
</div>

And here is some of my CSS:

body {
    background: #f5f7fa;
    padding-top: 3.5rem;
}
.content {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#side_nav {
    background: #ffffff;
    min-width: 300px;
    max-width: 300px;
    position: relative;
    border-right: 1px solid #cbd0dd;
}

Answer №1

This scenario is reminiscent of the setup in questions like How to create a flexible Bootstrap Navbar and content layout and this particular inquiry, as the principles of Bootstrap 5 flexbox remain consistent.

It's important to note the distinction between "100%" and "fill remaining height." In this case, achieving a layout where the main container does not exceed the viewport height while occupying the remaining space is the goal.

body {
    background: #f5f7fa;
    padding-top: 3.5rem;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}
.content {
    width: 100%;
    display: flex;
    justify-content: center;
}

#side_nav {
    background: #ffffff;
    min-width: 300px;
    max-width: 300px;
    position: relative;
    border-right: 1px solid #cbd0dd;
}

<nav class="navbar fixed-top custom-navbar"> Nav </nav>
<div class="main-container d-flex bg-light flex-grow-1 overflow-auto">
    <div id="side_nav" class="overflow-auto">
        <h1>sidebar</h1>
    </div>
    <div class="content overflow-auto">
        <h1>content</h1>
        ...
    </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

What is the correct method to include basic authentication headers in a post request for retrieving HTML content?

One of the projects I'm currently working on involves a POST endpoint that is protected by basic auth and returns an HTML form. This particular endpoint is hosted using an express server and secured with passport's basic auth. My goal is to creat ...

Using JQuery to enable the movement of divs on a screen through clicking and dragging, without the use of

Recently, I've been experimenting with a small project involving draggable divs. However, the code I've written doesn't seem to be functioning properly, causing JQuery to become unresponsive. Is there an alternative method that is simple an ...

Issues with Toggling Visibility in HTML, CSS, and Javascript

Currently, I am working on a website and following a tutorial called "Creating Slideshow using HTML, CSS, and Javascript" by W3Schools. In the project, I want to hide the thumbnail images located at the bottom and the navigation arrows initially and have t ...

Adjust the text color when hovering with the style tag

When it comes to customizing the color of a link on hover, CSS makes it simple with code like this: .myId:hover{ color:green; } But what if you're using inline styles? Is there a way to achieve the same effect without just plain HTML and CSS? & ...

Is there a way to make FullPage and Lightbox compatible with each other?

Currently utilizing Fullpage.js for my website, I am looking to incorporate a lightbox in one of the sections. However, upon attempting to load the script and CSS, my fullpage layout breaks and the sections collapse. I have experimented with placing the ...

Activate the front camera on an Android device using HTML5 or JavaScript

I'm currently working on a web app that needs to access the front camera of Android phones running version 4.0 or higher. After taking a picture, the app should then upload the captured image to my own server. Is there a way to launch the front camer ...

Delete any classes that start with a specific prefix

Within my code, there is a div that holds an id="a". Attached to this div are multiple classes from different groups, each with a unique prefix. I am uncertain about which specific class from the group is applied to the div in JavaScript. My goal is to r ...

Strange circle border appearance in Android / Chrome device

Having an issue with my code on a Samsung Galaxy S5 in Chrome 54.0.2840.85, Android 6.01. You can view the problematic codepen here: http://codepen.io/johnsonjpj/pen/jVpreB The border displays correctly on Firefox and iPhones, but not on my device. Trou ...

What causes jQuery's append function to trigger a redraw of my Div?

I have a unique function that incrementally increases the date by one day every second. Once the date matches specific dates, I aim to update my #newsDiv with extra text content. The #newsDiv will display all historical "news" and will be set to scroll to ...

What prompts certain individuals to convert their asp.net pages into HTML pages before publishing?

Recently, I was informed that there is a possibility of working on a project involving ASP.NET 3.5 and C#. A colleague suggested that when we publish the site, we should convert all pages to HTML. This means instead of www.test.com/Page.aspx, it would be w ...

CSS an act of misbehavior

I have noticed some unusual behavior on my website page. My website design can be viewed at Also, here is the same design in CMS format Please pay attention to the section under <div class="godelpage"> <a href="http://ryugaku.babonmultimedia ...

Using CSS to resize an element with both dimensions while maintaining its

Is it feasible to preserve a 1:1 aspect ratio on a div element using the CSS resize property? This particular illustration lacks an aspect ratio. Do you have any recommendations? ...

When the FLASK button is triggered, retrieve data from the FLASK and display it

This is a unique test where I will create a button to retrieve information from a MySQL database. However, it's important to first understand this concept. So here is my custom text within the Flask framework: @app.route('/pythonlogin/home', ...

The touch event doesn't seem to be functioning properly on the div element, but it works perfectly on the window element

I have a dilemma that's been puzzling me lately. I'm trying to append a touchevent to a div, but my current method doesn't seem to be working. Here's what I've tried: $("#superContainer").bind('touchstart', function(even ...

What is causing the issue with CSS properties and media queries not being effective on specific elements?

I have been experimenting with React and SCSS to create a portfolio page. Although I am familiar with these tools, I recently encountered issues where certain style changes were not reflecting in the browser. One specific problem involved styling the head ...

Next.js fails to update the user interface (UI) when there is a change in

In my latest Next.js project, I am working on a feature that involves looping through an array of amenities. Each amenity is displayed in a div element that, when clicked, toggles the active property. The logic behind this functionality is handled by the ...

Assistance needed with incorporating an additional link button into the extensive menu

I recently checked out the impressive mega menus featured on the w3schools website. You can find them here: (https://www.w3schools.com/howto/howto_css_mega_menu.asp). While using the "try it yourself" option, I tried to experiment with adding another mega ...

I am having trouble getting the pagination to function properly on my custom materialize projects

I am experiencing issues with the list of sub-pages on the official demo sites: Materialized Materialize(css) The navigation bar does not update the active page number or content when clicked. Both websites are using materialize css. If you click ...

Tips for preventing overlap between two divs when utilizing position: absolute in CSS

In this CodePen link [https://codepen.io/anon/pen/qvQpaY], there is an issue with overlay between the two divs that have a class name of box-container. The black rectangle is being counted as the overall height by box-container because the red rectangle is ...

What is the best way to reduce the size of an image taken from an image sprite rather than a standalone image?

I have an image sprite and I am looking to make a specific part of it appear smaller using CSS. Any recommendations or suggestions? Thank you in advance. ...