Guide to creating a fixed sidebar, right column, header, and footer with scrollable content utilizing flexbox styling

My goal is to create a webpage layout with a fixed header, footer, sidebar, and right column containing ads, while allowing the content to be scrollable. I attempted to achieve this by placing the header and footer outside of the flexbox, and using a wrapper for the middle page with flexbox for the 3 columns. I utilized the sticky property for the header and the fixed property for the sidebar. However, I am encountering the issue of the sidebar overlapping the footer, and I'm unsure of the cause. These are the challenges I am currently facing.

  1. There is an extra gap on the right side of the page horizontally after the content ends. Despite setting the width of the entire HTML body to 100%, the gap persists.
  2. The fixed sidebar is overlapping with the footer. I attempted to address this by adjusting the height using calc, but it did not resolve the issue.
  3. The ad column is scrolling after reaching the bottom, even though I used the sticky property. Ideally, it should remain fixed, right?
  4. Moreover, when I decrease the window size horizontally, the right column disappears while the middle, header, and main content adjusts. I tried setting the width of the wrapper to 100%, but the right column still vanishes. I want to find a solution without using the overflow property, and as a newcomer to flexbox, I'm struggling with keeping the columns fixed.

html body{
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: 'Roboto', sans-serif;
}
#top{
  position:sticky;
  top:0px;
  z-index:1;
}
#header{
  width: 100%;
  background-color: #32404d;
  position: relative;
  height: 85px;
}

#header img {
  width: 300px;
  position: relative;
  margin-left: 30px;
  top: 50%;
  transform: translateY(-50%);
}

#header p {
  float: right;
  position: relative;
  margin-right: 30px;
  top: 50%;
  transform: translateY(-125%);
  color: #dfe9ed;
  font-weight: 600;
}

.wrapper{
  display: flex;
  flex-direction: row;
}

#nav {
  height: calc(100vh - 90px);
  width: 200px;
  background:#4b5c6e;
  position:fixed;
}

.maincontent{
  margin-left: 200px;
  position: sticky;
  top: 85px;
  padding-left: 30px;
  margin-right: 30px;
  font-size: 15px;
  font-weight: 400;
  color: #343e47
}

#heading{
  color:#4b5c6e;
  width: 465px;
  border-bottom: 2.8px solid #313c47;
  font-size: 45px;
  margin-top: 20px;
  margin-bottom: 20px;
  line-height: 1.1;
  font-weight: 500
}

#right{
  width: 180px;
  height: calc(100vh - 90px);
  position: sticky;
  top:85px;
}
.ad{
  padding-top: 20px;
  background-color: #eaf2fa;
}
#htmlimg{
  padding-left: 20px;
  padding-top: 10px;
}

#footer-wrapper{
  width: 100%;
}
#footer {
  font-size: small;
  padding: 0.3em;
  height: 40px;
  color:white;
  background: #32404e;
  margin-bottom: 0px;
}
#footer p{
  float:right;
  position: relative;
  top: 0px;
  right: 40px;
  margin-left: 500px;
  margin-bottom: 0px;
}
<body>
  <header id="top">
    <div id="header">
      <img src="./images/logo1.svg " alt="logo" />
      <p >Welcome Tello</p>
    </div>
  </header>
  <div class="wrapper">
    <nav id="nav">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Process</a></li>
        <li><a href="#">Contact Us</a></li>
      </ul>
    </nav>
    <div class="maincontent">
      <p id="heading">Welcome to company</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu arcu quis lorem 
    </p>
      <p>Praesent volutpat tincidunt odio eu laoreet. Nullam pellentesque gravida leo, elementum 
    volutpat.</p>
    </div>

    <div id="right">
      <div class="ad">
        <img id="htmlimg" src="./images/html-5.svg " alt="logo" />
        <img id="cssimg" src="./images/css3.svg " alt="logo" />
      </div>
    </div>
  </div>
  <div id="footer-wrapper">
    <footer id="footer"><p>&#169 Tello inc.</p></footer>
  </div>
</body>/html>

Answer №1

Here are some suggested CSS styles to enhance your layout:

#right-column {
        height: calc(100vh - 134px);
    }

#footer-section {
    z-index: 1;
    position: relative;
}

.content-section {
    height: calc(100vh - 150px);
    overflow-y: scroll;
}

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

Can we pause and resume the progress bar using Javascript in conjunction with animationPlayState?

Looking for a way to control a progress bar script that runs for 180 seconds and then redirects the browser? Check out the code snippet below. I've added an onclick event to test pausing the progress bar. My goal is to pause, reset, and adjust the dur ...

Changing HTML elements dynamically within an ng-repeat using AngularJS directives

I have devised an angular directive where I execute an ng-repeat. The fundamental purpose of this directive is to interchange itself with a distinct directive that depends on a value forwarded into the original directive: <content-type-directive type=" ...

The ultimate guide to personalizing group titles in Angular UI-Select

Is there a way in Angular ui-select to customize the group label? I want to make it larger than the selection items as shown in the image below. https://i.stack.imgur.com/ofcak.png The list is currently grouped by country, but how can I adjust the size o ...

Utilizing jQuery for displaying or hiding list elements

To view all the code, click on this link: http://jsfiddle.net/yrgK8/ A section titled "news" is included in the code snippet below: <ul id="news"> <li><p>asfdsadfdsafdsafdsafdsafdsafdsafdsa</p></li> <li>&l ...

Debugging Slideshows Using JavaScript

I am currently working on creating a slideshow and I'm facing some challenges with the JavaScript functionality. Everything seems to be running smoothly except for one issue - when I click right once, it transitions correctly, but if I then click left ...

Troubles with Sizing in Twitter Bootstrap Modal

One issue I have encountered with my application is the varying widths of modals. Setting the width inline works well, but when the window is compressed it can cause part of the modal to be off screen, rendering it useless at smaller resolutions such as th ...

When using Angular, automatically shift focus to the next input field by pressing the

I am faced with a challenge involving multiple editable inputs on my screen. Alongside these editable inputs, there are buttons and disabled inputs present. The current behavior is such that when I press Tab, the focus shifts to the HTML elements between ...

Encountering an issue with Nuxt 3.5.1 during the build process: "ERROR Cannot read properties of undefined (reading 'sys') (x4)"

I am currently working on an application built with Nuxt version 3.5.1. Here is a snippet of the script code: <script lang="ts" setup> import { IProduct } from './types'; const p = defineProps<IProduct>(); < ...

The print preview displays a single div in an incorrect location

I have successfully created a javascript plot and wanted to incorporate a legend that overlaps the plot. Unfortunately, the function I used does not support directly overlapping legends, but it does allow for placing the legend in a separate div. To work a ...

Achieve video lazy loading in JavaScript or jQuery without relying on any external plugins

I've been experimenting with lazy loading videos using jQuery. While I've had success with lazy loading images and background-images using the same technique, I ran into issues when trying to apply it to videos. Here's what I've tried s ...

The click event triggered by the onclick clone/function may not always activate the click handler

As a newcomer in the JavaScript domain, I am encountering an issue where the first clone created after clicking 'add more' does not trigger my click me function. However, every subsequent clone works perfectly fine with it. What could be causing ...

Determining the length of an array of objects nested within another object

I received a response from the API called res. The response is in the following format: {"plan":[{"name":"ABC"},{"name":"DEF"}]}. I am attempting to save this response in my TypeScript code as shown below: ...

Create a pagination system in CodeIgniter for displaying data

Having trouble implementing paging in the search functionality of my result table. I want to display just 10 rows but can't get it to work properly. I tried reading about Pagination on https://codeigniter.com/, but I'm still struggling to unders ...

What is causing the failure of generating a DIV element with JQuery?

I'm having trouble creating a div element with a class and appending a child to it. I keep getting no response. What could be the issue? JS content function generateTable() { var procDiv = $("<div class='proc-container'></div>" ...

Is it possible to include a border/stroke on a Raphael picture?

Currently, I am attempting to enhance a Raphael image element by adding either a border, stroke, or drop shadow. My end goal is to create an animated glowing border effect. Previously, I successfully implemented this on traditional HTML elements using Java ...

Position the scroll down arrow at the center bottom of a full-screen div using WPBakery Visual Composer

I have a series of full-screen sections in Visual Composer and I am trying to add an arrow at the bottom of each one to indicate to users that they should scroll for more content. However, my attempts with absolute positioning on the divs containing the ic ...

Disable hover effects in CSS with JavaScript

I am looking for a way to deactivate CSS hover functionality using JavaScript. Within a form, there is a button that sends data to the database server. By utilizing OnClientClick() of an ASP.NET Button control, my goal is to modify the text of the element ...

Tips for transmitting dropdown selections to a different PHP form using jQuery

After spending a considerable amount of time searching for answers online, I realized that I need some help. Despite finding helpful articles and resources on jQuery, I am still struggling to understand certain concepts. As a beginner in this field, I am w ...

Ensure that the innerHTML of the span tag does not contain line breaks

Is there a way to prevent the span tag inside the div with the item class innerHTML from causing a line break, regardless of its length? I also need to ensure that any innerHTML exceeding the item width does not overlap but is hidden. I have attempted usin ...

What is a way to create a colored <hr> element without increasing its height at all?

I'm facing a dilemma - I created an hr element and it's currently grey, but I want to change the color to black. The issue is that when I do this, it appears thicker and ruins the overall styling of my page. Does anyone have any ideas on how I ca ...