Display a scrollbar for the offspring of an element with a flex-grow value of 1

I'm seeking to create a straightforward design consisting of a layered header, main section, footer.

My framework of choice is bootstrap 5.

The complete layout should occupy all available width and height, with overflow (x and y) set to hidden.

Header and wrapper should expand to the necessary space.

Main section needs to be sandwiched between the header and footer, taking up all available width. Main section is comprised of a sidebar and an area for the main content.

Sidebar and main content are aligned side by side. Sidebar should occupy 1/6 of the total available width. The main content should take up the remaining width available.

Here is a snippet of the code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30525f5f44434442514070051e011e03">[email protected]</a>/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
      crossorigin="anonymous"
    />

    <title></title>
  </head>
  <body>
    <div class="d-flex flex-column wrapper">
      <div>
        <nav class="navbar navbar-light header">
          <div class="px-3">
            <a class="navbar-brand" href="#">
              Header
            </a>
          </div>
        </nav>
      </div>
      <section class="flex-grow-1 d-flex section">
        <div class="col-2 sidebar">
          <ul class="nav flex-column menu-nav">
            <li class="nav-item px-3 py-2">
              Sidebar
            </li>
          </ul>
        </div>
        <div class="col p-2 px-3 content">
          Main content
        </div>
      </section>
      <nav class="navbar navbar-light header">
        <div class="px-3">
          Footer
        </div>
      </nav>
    </div>
  </body>
  <style>
    body {
      height: 100%;
      width: 100%;
      overflow: hidden;
    }

    .header {
      background-color: #1ea185;
    }

    .wrapper {
      height: 100vh;
    }

    .section {
    }

    .sidebar {
      height: 100%;
      overflow-y: auto;
      background-color: #fff;
    }

    .content {
      height: 100%;
      overflow-y: auto;
      background-color: #eff6f6;
    }
  </style>
</html>

I want the overflow-y to be visible for sidebar/main content only when necessary, while maintaining the position of the footer.

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

Answer №1

<div class="col p-2 px-3 content relative">
      <div class="absolute inset-0 overflow-y-scroll"> 
          Main content
      </div>
    </div>

Arrange the .content container as relative, then place the content in an inner div with absolute inset-0.

Note: The example above uses tailwind syntax for the classes, but bootstrap may have slightly different class names.

<!DOCTYPE html>
<html lang="it">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c7e7373686f686e7d6c5c29322d322f">[email protected]</a>/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
      crossorigin="anonymous"
    />

    <title></title>
  </head>
  <body>
    <div class="d-flex flex-column wrapper">
      <div>
        <nav class="navbar navbar-light header">
          <div class="px-3">
            <a class="navbar-brand" href="#">
              Header
            </a>
          </div>
        </nav>
      </div>
      <section class="flex-grow-1 d-flex section">
        <div class="col-2 sidebar">
          <ul class="nav flex-column menu-nav">
            <li class="nav-item px-3 py-2">
              Sidebar
            </li>
          </ul>
        </div>
        <div class="col p-2 px-3 content relative">
          <div class="absolute inset-0 overflow-y-scroll"> 
              Main content
          </div>
        </div>
      </section>
      <nav class="navbar navbar-light header">
        <div class="px-3">
          Footer
        </div>
      </nav>
    </div>
  </body>
  <style>
    body {
      height: 100%;
      width: 100%;
      overflow: hidden;
    }

    .header {
      background-color: #1ea185;
    }

    .wrapper {
      height: 100vh;
    }

    .section {
    }

    .sidebar {
      height: 100%;
      overflow-y: auto;
      background-color: #fff;
    }

    .content {
      height: 100%;
      overflow-y: auto;
      background-color: #eff6f6;
    }
  </style>
</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

Utilize a button to apply styles to a Span element dynamically generated with JavaScript

I am attempting to spin a span generated using JavaScript when a button is clicked. The class is added to the span, but the spinning effect does not apply. <p>Click the button to create a SPAN element.</p> <button onclick="myFunction ...

Utilizing the Jquery hover feature to reveal or conceal an element

My Hover function is designed to display and hide sub menus when a person hovers on them. The issue I'm facing is that the menu disappears when I move the mouse down towards it. Can someone help me identify what I am doing wrong here? ...

Is it possible to toggle all parent targets in Bootstrap?

When trying to showcase my point, I believe it is best demonstrated by visiting Bootstrap documentation at https://getbootstrap.com/docs/4.0/components/collapse/ and viewing the "multiple targets section." In this section, you will find three buttons: togg ...

The li elements within a 960.gs layout will not extend to fill the entire width of the

I am still learning about this and I have been following some tutorials online. I managed to make the columns work with paragraph tags, but when I use ul > li tags, the image takes up the entire space. I'm not sure what's causing this issue. ...

Is CSS General sibling selector not functioning properly when used with :focus?

How can I display text that turns into an input form when hovered over, and stays visible even if it's unhovered but the user is interacting with the input form? The issue is that when the input form is focused while unhovered, both the input form an ...

Looking to incorporate Bootstrap Icons within Semantic UI?

I'm in need of assistance. My current project involves using Semantic UI, but there's a requirement to incorporate Bootstrap icons from . However, I'm facing difficulty copying the svg information directly into the code for the sake of reada ...

chaotic telerik editor arrangement

I have incorporated the Rad Editor into my ASP.NET page. <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <telerik:RadEditor ID="reSummery" runat="server" > </telerik:RadEditor> Despite not referencing ...

What is the optimal HTML tag for showcasing chat text conversations?

To create a text window with fixed width and length that automatically wraps long texts without a horizontal scroll bar but with a vertical one, you can use HTML and CSS. The preview window on SO's ask question page is a good example of this. It is si ...

Eliminating the appearance of horizontal scroll bar by employing transform scale to zoom out

When you run the code provided in the link below and scale down the HTML to 50% while increasing the width to fit the window, a scrollbar becomes visible. This only occurs in Chrome and not in Firefox. Click here The content of the DOM can be modified and ...

What is the process for utilizing npm/yarn installations within a .Net Framework WebAPI project?

In my project, I utilize SCSS and would like to incorporate Bootstrap.scss in order to create a single class that inherits multiple Bootstrap classes. For instance: .myButtonClass { @col-xs-12; @col-sm-6 } This way, I can replace class="col-xs-12 col-sm- ...

Guide on implementing event listener for right click using pure JavaScript (VANILLA JS)

I need the div to appear wherever the cursor is holding down the right mouse button. In my scenario, I am using the following code: <div class="d-none" id="item"></div> #item{ position: absolute; top: 0; left: 0; w ...

Struggle with Firefox: Table-cell with Relative Positioning Not Acting as Parent

Upon investigation, I have come across a unique layout issue that seems to only affect Firefox. It appears that elements with display:table-cell; do not act as the positional parent for descendants with position:absolute;. It is surprising to discover th ...

Seeking ways to ensure my component maximizes available space using Tailwind CSS

I am currently utilizing Tailwind CSS to style a Angular application. The setup is fairly straightforward: app.component.html is responsible for displaying a navigation bar and footer, while the components are shown in the remaining space with an overflow- ...

Applying CSS to align the first line to the left and right, while ensuring that wrapped lines are aligned to the

Struggling with CSS to align drink names and descriptions on a bar's menu. Want the name left aligned and the description right aligned, even if wrapped lines are also right aligned. Current progress can be seen at http://jsfiddle.net/H96XQ/ CSS: . ...

displaying a div upon checking the checkbox

How can I make a div push the content below it when it is in the show state? Currently, when I check the checkbox, the textarea covers the submit button, hiding it. Is there a way for the textarea to push the button down instead? You can find my code here: ...

What is the procedure for eliminating the underline located at the bottom of the table?

Can anyone please assist me with removing the underlines at the end of the table? I find it quite unattractive and can't seem to figure out how to remove it. https://i.sstatic.net/stvHt.png https://i.sstatic.net/YYbrX.png Below is the code snippet ...

What is causing the text to not wrap around properly?

I'm currently facing an issue where the text that should not wrap around the image is wrapping, while the text that should be wrapped isn't. This is causing a layout problem in my coding section as shown here: https://i.sstatic.net/2oMn1.png The ...

Tips for hiding the overflow scrollbar on Microsoft Chrome when there is no content to scroll

Looking for a solution to hide scroll bars in Microsoft Chrome, but only when there is no content to scroll? The current div and styles always show the horizontal and vertical scroll bars, even when the height exceeds the content. <div style="backgroun ...

Update the picture displayed in the parent div when it is in an

My code currently changes the image when a parent div is in an active state, but I'm struggling to figure out how to revert it back to the original image when clicked again. I attempted to use 'return false' at the end of the script, but it ...

Tips for creating two lines of text within one line using CSS

My explanation skills are not the best. I have the words "Tasty Burger" stacked on top of each other, but I want them to be on a single line. .footer-container { margin: 25px 0; display: flex; gap: 3rem; align-items: center; justif ...