Creating a CSS layout using Flexbox that includes a header, footer, and a sidebar that is partially

After exploring numerous suggestions from different sources, I am facing a common issue where the scroll bar appears on either the body or the content area, causing the header to occupy space and push the content downwards.

Specifically, the requirements are as follows:

  • Body should remain non-scrollable
  • Header and footer must be fixed
  • Searchbox should not scroll
  • Search results need to be scrollable
  • Utilizing ngx-split, implying the usage of flexbox

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

This scenario is reminiscent of similar inquiries such as:

  • However, this includes an additional non-scrollable box in the sidebar: Layout with fixed header and footer, fixed width sidebar and flexible content

  • Additionally, with a footer involved: Scrolling a flexbox with overflowing content

Answer №1

To successfully structure the layout, follow these three steps - each step employing a distinct flex layout and flex-direction.

  • page-wrapper
    • page-header
    • page-content
      • left-column
        • left-column-header
        • left-column content
      • right-column
    • page-footer

1. Organize the header / content / footer using display: flex; flex-direction: column; with flex-grow applied to the content - this positions the header and footer at the top and bottom of the viewport while enabling the content to expand and fill the remaining space.

2. Arrange the left and right columns by utilizing display: flex within the page-content area; (note that the default direction is "row" so no need to specify it).

3. Design the left-column-header and content by implementing display: flex; flex-direction: column; for the left column and adding max-height and overflow-y: auto to the left-column-content

html, body {
height: 100vh;
overflow: hidden;
padding: 0;
margin:0
}

ul {
margin: 0;
padding:0;
list-style: none;
}

.page-wrapper {
  display: flex; 
  flex-direction: column;
  border: solid 1px #222;
}

.page-header, 
.page-footer {
  height: 30px;
  flex-shrink: 0;
 line-height: 30px;
 padding: 0 8px
}

.page-content {
  border-top: solid 1px #222;
  border-bottom: solid 1px #222;
  flex-grow: 1;
  display: flex;
}

.right-column {
 width: 60%;
 flex-grow: 1;
 border-left: solid 1px #222;
 padding: 8px 16px
}

.left-column {
 width: 40%;
 flex-shrink:0;
 display: flex; 
 flex-direction: column;
}


.left-column-header {
  height: 40px;
  flex-shrink:0;
  align-items: center;
  border-bottom: solid 1px #222;
  display: flex;
}

.left-column-header div {
  flex-grow: 1;
  padding: 4px 8px
}

.left-column-content {
  overflow-y: auto;
  max-height: calc(100vh - 100px);
  padding: 0 8px
}
<div class="page-wrapper">
  <div class="page-header">Header</div>
  <div class="page-content">
    <aside class="left-column">
      <div class="left-column-header"> 
        <div class="search-input-wrapper">
          <input type="text" placeholder="Search" />
        </div>
        <div class="search-button-wrapper">
          <button type="button" >Button</button>
        </div>
      </div>
      <div class="left-column-content">
       <ul>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
         <li>Search results</li>
       </ul>
      </div>
     </aside>
    <main class="right-column">Right column</main>
   </div>
  <div class="page-footer">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

Developing bi-directional binding for newly generated elements post initial compilation

I have developed a directive that dynamically generates a form based on a JSON received from the server. I am trying to include the ng-model attribute in the input elements so that I can access the input values once the user enters them and clicks submit. ...

Creating a circular shape with segments using HTML, CSS, or JavaScript

My goal is to create a circular shape with segmented sectors without relying on external images. I am looking to achieve something like the example image provided below: I am open to utilizing HTML, CSS, or jQuery for this task, but if those options are n ...

What is the best way to insert an image that is absolutely positioned inside a <td>?

I'm facing an issue with placing an absolutely positioned image inside a td. The code I have tried seems to create gaps above the image in FF 3.6 and causes the image to disappear in IE 7. I have included the necessary external style sheet elements ab ...

Customize the background color of a clipPath in SVG

I'm looking to design a landing page featuring a colored div with a clip-path, intended to showcase a video playing in the background. However, I'm encountering an issue where the background looks grayish without any clear explanation. Despite t ...

The Selenium driver's execute_script() function is not functioning as expected

When I attempt to execute a JavaScript using driver.execute_script, nothing happens and the system just moves on to the next line of Python code. Any ideas? I've been web scraping on a webpage, using JavaScript in the Console to extract data. The Jav ...

Navigate the child div while scrolling within the parent div

Is there a way to make the child div scroll until the end before allowing the page to continue scrolling when the user scrolls on the parent div? I attempted to use reverse logic Scrolling in child div ( fixed ) should scroll parent div Unfortunately, it ...

Choosing the right framework for implementing push notifications can be a critical decision. Should

I am currently working on a Java application that requires the server to send push notifications to the client every one second. To achieve this, I am using HTML5 server-sent events for one-way communication from the server to the client. However, my conce ...

Click on the link within the Checkbox label on MUI

I am working on creating a checkbox for the "Terms of Use," using FormControlLabel to nest a Checkbox. However, I also need to include a link that opens a Dialog component displaying the terms. The challenge is that clicking on the link checks the checkbox ...

Get a list of all languages supported by browsers using JavaScript

Within my HTML user interface, I have a dropdown that needs to display a list of all installed browser languages except for the first one. I managed to retrieve the first language (en-us), but I also have the zh-CN Chinese pack installed on my operating s ...

Create a new variable and compile the sass/less file when it is requested

I'm exploring options to utilize Node.js or another server-side language to handle a specific type of request. For instance, receiving a request like this: The goal is to extract the value from the URL parameter and use it to dynamically update a var ...

Ways to eliminate the navigation button on an HTML5 video player

I'm having a great experience using the HTML5 video player to continuously play videos. However, I have noticed that when my mouse cursor hovers over the video, a navigation button appears at the end of the screen. I would like to either remove or hid ...

How can I expand my Jquery slideshow to occupy the entire screen?

I am working on stretching my JQuery slideshow to fit the entire browser, but I am running into some difficulty. I have downloaded the jQuery Vegas plugin, but I can't seem to figure out what the problem is. I would like my slideshow to resemble the o ...

"Enhancing User Experience with Bootstrap's Smooth Transition Effects for fadeIn() and fade

As someone who is new to html and JavaScript, I have the following html code: <div class="row" > <button class="..." id="button"> ... </button> <div class="..." id="box"> ... </div> </di ...

Creating a mouse-resistant div with a magnet-like effect

Looking for a way to make a circle move like a magnet effect when the mouse is near, causing elements underneath it to be exposed. If you want to see an example, check out this fiddle link: http://jsfiddle.net/Cfsamet/5xFVc/1/ Here's some initial c ...

Is the parent node of the input element the input element itself?

When working with a DOM object obj of type <input>, I encountered an issue where attempting to obtain its parent node using obj.parentNode resulted in the same obj being returned. Is this behavior specific to <input> objects? What other types o ...

Leveraging Modernizr for identifying drag and drop functionalities

On my website, there is a section that requires drag and drop functionality in HTML5. I want to inform users on the homepage if their browser supports this feature. Despite attempting to use Modernizr, I have not been successful. I generated a custom file ...

What is the best way to apply a 2px padding to text-decoration: underline?

As a dedicated frontend developer, I believe in creating underlines with a 2px padding instead of the default 1px. Is there an easy solution for achieving this? PS: Yes, I am aware of using a div with a black background color and 1px * Npx with position: ...

Troubleshooting issues with adding rows to an HTML table

I want to include two buttons at the top of my page: Save and Cancel. These buttons should only appear after clicking the Submit button on the Customer Information panel. However, when trying this, the Customer Information panel is pushed down while I al ...

having difficulty grasping the variable's scope within this code

Here we have a code snippet where the variable vid is initialized inside a function. The question arises on how this variable can be used outside the function, specifically in the context of vid.play(). How does the program know that vid was created usin ...

The Bootstrap row fails to align elements side by side as intended

I'm trying to arrange elements in my navigation menu side by side, so I decided to use the row class from Bootstrap 5.0. However, they are still stacking on top of each other. I am currently working on a Flask project and using Jinja to some extent. ...