Creating a Bootstrap 4 layout where columns have 100% height and internal scroll capability

Is it possible to achieve this specific layout using only Bootstrap 4?

  +-------------------------------------------------+
  |               Navbar fixed on top               |
  +------------+------------------------------------+
  |            |                                    |
  |            |                                    |
  |Column A    |Column B                            |
  |            |                                    |
  |            |                                    |
  |            |                                    |
  |            |                                    |
  |            |                                    |
  |            |                                    |
  +------------+------------------------------------+
  |                  Fixed footer                   |
  +-------------------------------------------------+

I need to ensure that Column A and B expand to fill the remaining space, covering the full screen without any scrolling at the body level. However, if their content exceeds the available space, I want them to scroll independently of each other - meaning scrolling in Column A should not affect Column B and vice versa. Additionally, how can I hide the scroll bars?

Answer №1

Hey there, I put together this code for you to take a look at. The main idea here is that I fixed the positioning of certain sections and set the overflow property to scroll.

.header {
  position: fixed;
  width: 100%;
  background-color: blue;
  top: 0;
}

.footer {
  position: fixed;
  bottom: 0px;
  width: 100%;
  background-color: red;
}

.content{
 
  margin: 25px;
  overflow: hidden;
  position: fixed;
}

.a {
  width: 25%;
  float: left;
  overflow: scroll;
  height: 100vh;
}

.b {
  width: 75%;
  float: left;
  overflow: scroll;
  height: 100vh;
}
<div class="header"> This is the header</div>
<div class="content">
<div class="a">
Content of column A goes here
</div>
<div class="b">
Content of column B goes here
</div>
</div>
<div class="footer"> This is the footer</div>

Answer №2

In my comment, I suggested using the standard Bootstrap grid layout to achieve the desired design.

row no-gutters

col

The maximum value of columns is 12 in Bootstrap layouts. More information on this can be found here.

To control the heights of containers, you can utilize the view height property in CSS by setting height: [number]vh;

For enabling scrolling functionality, consider using the CSS property overflow. Choices include auto or scroll - overflow: auto;

Here's a hypothetical representation:

HTML:

<nav class="navbar" id="mainNav">
    <div class="container">
        NAV
    </div>
</nav>
<div class="wrapper">
    <div class="row no-gutters">
        <div class="col-md-4 my-custom-class">
            Column A
            <br /><br />
            // Insert relevant content here
        </div>
        <div class="col-md-8 my-custom-class-2">
            Column B
            <br /><br />
            // Insert relevant content here
        </div>
    </div>
</div>
<div class="row no-gutters">
    <div class="col-md-12 custom-footer">
        FOOTER
    </div>
</div>

CSS:

.my-custom-class{
    background-color: blue;
    height: 75vh;
    color: white;
    overflow: auto;
}
.my-custom-class-2{
    background-color: red;
    height: 75vh;
    color: white;
    overflow: auto;
}

#mainNav{
    background-color: purple !important;
    color: white;
    height: 10vh;
}

.custom-footer{
    background-color: green;
    height: 15vh;
    color: white;
    text-align: center;
}

Runnable code snippet:

.my-custom-class{
background-color: blue;
height: 75vh;
color: white;
overflow: auto;
}
.my-custom-class-2{
background-color: red;
height: 75vh;
color: white;
overflow: auto;
}

#mainNav{
background-color: purple !important;
color: white;
height: 10vh;
padding-bottom: 8%;
}

.custom-footer{
background-color: green;
height: 15vh;
color: white;
text-align: center;
padding: 5%;
}
// Insert corresponding HTML and link bootstrap stylesheet before including navbar component

// Insert example content for columns A and B, observing assigned classes

See how it displays in a browser environment by visiting this link.

Screenshot preview available here: https://i.sstatic.net/4AhDy.png

Answer №3

It is recommended to set a specific height for your div up to 100vh. This ensures that when the content exceeds more than 100% of the height, the built-in Bootstrap class overflow-auto will automatically apply a scroll bar to the div.

#header {
  position: absolute;
  height: 50px;
  background-color: brown;
  width: 100%;
}

#body {
  position: absolute;
  top: 50px;
  bottom: 50px;
  background-color: yellow;
}

#footer {
  background-color: red;
  position: absolute;
  height: 50px;
  bottom: 0;
  width: 100%;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
  <title>Hello, world!</title>
</head>

<body>
  <div id="header">Header</div>
  <div id="body" style="overflow-x: hidden;">
    <div class="row">
      <div class="col-4 overflow-auto" style='height: 100vh;'>Sample text here.</div>
      <div class="col-8 overflow-auto" style='height: 100vh;'>More sample text here.</div>
    </div>
  </div>
  <div id="footer">Footer</div>
  
</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

What is the best way to display link text when the sidebar is collapsed on Angular 9?

Is it possible to have the anchor tag's title attribute, like title="link name", only show up when the navbar is collapsed? I have multiple links in the HTML file but to keep things concise, I've chosen to display only a few. This is the .html t ...

What are some tips for customizing the NavBar Bootstrap 4 Layout to fit a unique design?

Good evening everyone, I am currently working on a website project for a client who has provided me with specific requirements for the Navbar design. While it seemed straightforward at first, I have spent several hours trying to perfect the layout. I am ...

Tips for making an appended element match the height of an image

After embedding the div .soonOverlay into specific .smallCatalogBlock's, I am facing difficulty in adjusting the height of soonOverlay to match only the height of the img within smallCatalogBlock. Currently, its height extends throughout the entire co ...

Issue with DIV positioning in IE when another DIV is animated downwards

Here's how my page structure looks like: <header> <div class="slide"> <!---- some elements here ---> </div> <nav> <ul> <li id="open"></li> <! --- other parts of the navigation ...

What CSS property can be used to make short words wrap to the next line?

Is it possible to automatically identify if a line of text ends with a short word and then move it to the next line, so that the text flows smoothly? This would ensure a more organized layout. For instance, I envision the following text: Cascading Style ...

What is the method for setting a cell's row-span to 2 using bootstrap?

Is there a way to make the red cell in a Bootstrap grid have a row-span=2 and fill the second row as well? .cell {height: 100px; border: 1px solid; border-collapse:collapse;} .red {background: red;} .yel {background: lightyellow;} <link href="https:/ ...

What steps can be taken to ensure this website is responsive and includes a countdown counter?

I have recently created a website (http://koulick-project.surge.sh/) as a project, but I am facing challenges in making it fully responsive. I have been able to make the headings and text responsive, however, I am struggling to make the circles for the clo ...

The button in the flex container is not wide enough due to center alignment

For my project, I implemented a CSS grid layout consisting of 20 rows and 20 columns (5% of screen for each cell). One particular page includes a button that initially fit within grid columns 5-8 and rows 6-9 without any issues. However, I wanted to center ...

Difficulty arises with z-index when hover effects are applied to clip-path shapes

I'm encountering an issue where I am attempting to make two clip path polygons overlap each other when hovered over by the mouse. I have been using z-index values and trying to adjust them based on which overlay is being hovered over, but unfortunatel ...

Create a webpage layout using Bootstrap that features a left-aligned image within a div, with

Is there a way to achieve this layout using Bootstrap? View the desired design I am looking to create a div with an image on the left (float:left) and text (which could be one or multiple lines) along with a button aligned to the bottom right. The goal i ...

How to style multiple tags using CSS

Is there a way to style specific tags in CSS? <style type="text/css"> [attribute*="test"] { background-color: red; } </style> However, this method does not seem to work for the following tags: <test-1> </test-1> <t ...

spontaneous generation of web page elements

I want to implement a coverflow using the plugin found at this link: Here is an example of how it can be done: <div class="coverflow"> <div class="cover">A</div> <div class="cover">B</div> ... <div class=" ...

Create a collapsible menu using only CSS that expands when the down arrow is clicked, specifically designed for

I am currently working on creating a mobile-friendly version of a menu. I have a list of items, and I want only the item with the class nav-current to be displayed initially. Using pseudo :after, I added an arrow after the link of that specific li element. ...

Tips for continuously duplicating a value in every textbox until the final one

I am looking to implement a feature where the value of a double-clicked textbox is repeated until the end of the textbox. In my form, there are ten text boxes with different values. When I double click on the third textbox, I want the value of the third te ...

The burger icon in the navigation bar is malfunctioning, showing just a single horizontal line instead

I've been working on creating a responsive layout button that resembles the following design: https://i.sstatic.net/v5vDd.png However, I've encountered an issue where I can't seem to generate all three horizontal lines, only one of them. T ...

What would you name this particular element?

I want to create a unique slider design but I'm unsure where to begin or how to search for information because I don't know the correct terminology. Does this type of slider have a specific name? I heard about Marquee, but that seems like someth ...

In HTML, favoring the use of "//domain.com" over "https://domain.com" or "http://domain.com" is recommended for greater flexibility and compatibility

Related Questions: Changing all links to // Network-Path Reference URI / Scheme relative URLs I have noticed some websites using the following format: background:url(//cdn.domain.com/images/bg-normal.png) They utilize "//", which the browser aut ...

Positioning an asp:Button to the right of the asp:Wizard's Next Button

Development Platform: ASP.NET C# Components Used: asp:Wizard and asp:Button I am facing an issue with my asp:Wizard where the additional button I want to place is rendering below the wizard instead of beside the Next Button. Is there a way to resolve ...

Customizing Mouse Pointers in CSS

My goal is to customize the click pointer on a website using CSS. I have successfully changed the default cursor, but now I am seeking help in changing different 'versions' of the cursor. Here's my current attempt at customizing the pointe ...

Is there a way to dynamically count the length of an element or class in realtime using JavaScript?

If there are currently 5 divs with the class name "item" and a new unknown number of divs with the same class name "item" are dynamically added in real time, I want my result to display the total number of divs present at that moment (i.e., 5 + n). Note: ...