Creating a Fixed Column in Bootstrap 4 with Proper Footer Alignment

I am currently working on a webpage layout that includes multiple columns, a header, and a footer. One of my requirements is to have a column scroll along with the user's navigation but not overlap the footer section:

    <html>
    <head></head>
    <body>
        <div id="wrap">
            <div id="main" class="clear-top">
                <div class="col-lg-12">
                    <div class="row pl-4 justify-content-between pb-4">
                        <div class="col-lg-1 col-md-12 col-sm-12 ">
                         </div>

                         <div class="col-lg-7 col-md-12 col-sm-12 ">
                             ... Main Content ... 
                         </div>

                         <div class="col-lg-4 col-md-12 col-sm-12 p-4 sidebar-container">
                            ... Scrollable Content ...
                         </div>

                    </div>
                </div>
            </div>
        </div>
    </body>

    <footer class="footer">
        <div class="container">
        </div>
    </footer>
</html>

CSS:

// General Styling 
html, body{
    height: 100%; 
}

#wrap {
    min-height: 100%;
}

#main {
    overflow:auto;
    padding-bottom:150px; /* needs to be greater than footer height */
}

.footer {
    position: relative;
    margin-top: -150px; /* negative value equivalent to footer height */
    height: 150px;
    clear:both;
    padding-top:20px;
    width: 100%;
    bottom: 0; 
} 

Despite using Bootstrap 4, I attempted adding the sticky-top class to the scrolling column but did not see any changes.

Trying to modify the position property to sticky for the column also did not produce the desired effect. Could it be that I added this property to the wrong div?

Answer №1

It seems like you are in need of a floating sidebar that moves along with the content. If that's the case, here is a solution for you. By using the sticky-top class, your side-nav will stick to the top without needing any CSS adjustments for the footer alignment. Simply apply the bootstrap classes d-flex flex-column min-vh-100 to your main container and add mt-auto to your footer to align it at the bottom of the page.

.custom-container {
  height: 500vh;
}

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

footer {
  background: yellow
}

#side-nav {
  background: blue;
  height: 100%
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container-fluid d-flex flex-column min-vh-100">
  <div class="row">
    <div class="col-sm-4">
      <div id="side-nav">
        <ul class="sticky-top text-center">
          <li><button id=1>Link1</button></li>
          <li><button id=2>Link2</button></li>
          <li><button id=3>Link3</button></li>
        </ul>
      </div>
    </div>


    <div class="col-sm-8 ">
      <div class="custom-container">
        <h2>Content that scrolls</h2>
        <h5>What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a
          type specimen book it has?</h5>
      </div>
    </div>
  </div>
  <footer class="mt-auto">footer</footer>
  </body>
</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

Creating Tab-Focused Accessibility in HTML Fragment (Modal Window)

I'm currently working on an Angular App with a custom Modal Dialog implementation. I'm trying to figure out how to restrict tabbing to just the elements within the Modal, rather than allowing users to tab through everything in the background. I ...

Troubleshooting: Why isn't my Bootstrap glyphicon icon displaying

Has anyone encountered issues with the glyphicon icon not showing up on buttons in Safari or Chrome when using Bootstrap? I tried fixing it but couldn't. Any help would be greatly appreciated! <link href="css/bootstrap.min.css" rel="stylesheet"&g ...

What is the best way to ensure Font-Face loads fonts successfully on iOS devices?

In the process of constructing a website with Gatsby.js, Styled-Components, and a custom font named 'Montserrat', I encountered an issue regarding font loading. The font appears as expected on desktop browsers during both build and hot-reloading, ...

Ensure the first column is fixed and all other columns have the same height

I have encountered an issue where the first column of my table has varying heights compared to the other columns, resulting in inconsistent row heights. Below is the code I am using: <div class="outer"> <div class="inner"> <table> ...

Creating a seamless integration of header, content, and footer components within html2pdf

After creating an HTML page, I utilized the html2pdf library to convert it into a PDF format. Here is the code snippet: <?php require('../admin/html2pdf/html2pdf.class.php'); ob_start(); ?> <page> <page_head ...

What is the best way to generate two <div> elements, with one of them being centrally fixed?

When it comes to CSS, I must admit that it's not my strong suit. My current challenge is to create two boxes or divs where one remains fixed in the center of the page, while the other adapts and positions itself right next to the first one. Essentiall ...

Error: Sveltestrap Tooltip encounters a ReferenceError due to process not being defined in the createPopper.js file

Looking for assistance with integrating Tooltip in Svelte using SvelteStrap. Below is a simple example: <script> import { Button, Tooltip, } from 'sveltestrap'; </script> <Button id="btntest">t ...

Image expansion

I have a container element div that holds various content of unknown length. How can I add a background image that extends the entire length of the container since background-images do not stretch? I attempted to use a separate div with an img tag inside. ...

Tips for printing a page to match its on-screen appearance

I am in the process of developing a scheduling page within ASP.NET Web Forms, incorporating custom CSS. I have successfully added a print button, but when I try to print the page, the CSS styles are not being applied. How can I resolve this issue? This is ...

Creating a shape image border with a clickable container can be achieved by using a combination of HTML and CSS

I'm trying to achieve the border effect shown in the picture while keeping the area under the frame clickable. I've tried using a div on top of another div, which works, but the bottom div is not clickable. I also attempted using a border image, ...

Local HTML files are failing to link with CSS, whereas everything is functioning properly on Github Pages

Working on a beginner Web Development project, I encountered an issue with linking my CSS file to my portfolio. The page displays correctly on GitHub pages, but fails to load properly when accessed locally on any browser even after clearing the cache. He ...

Slender Ebony Edging Surrounding a Table

I am trying to achieve a very thin border for the entire table, similar to what is shown in the image above. However, my current solution is not working as expected and the table is not displaying any borders at all. Below is the CSS I am using: table { ...

The tooltip for the Google+ button stopped working

After setting up my Portfolio, I added a Google+ button. However, the page lacks styling and there seems to be an issue with the tooltip causing delays. Can anyone help me identify where the problem lies? ...

Using Bootstrap cdn in my React JS project caused conflicts with my custom CSS styles

I recently created a webpage in ReactJS and styled it using CSS. In order to enhance the styling of one component, I integrated Bootstrap by adding the latest CDN link to my "index.html" file. However, I noticed that the Bootstrap styles were overriding ...

The color of hyperlinks in firefox varies based on the specific URL being visited

I am a beginner in the world of html and css. I have two links placed consecutively. In my css file, I have defined classes for a:link and a:hover. However, I noticed that the second link is displaying a purple color instead of silver. Both links correctly ...

Is there a way to trigger the opening of a new file or page when a CSS animation comes to an end?

Is there a way to delay the loading of a function or page until after an animation has finished running in JavaScript, HTML, and CSS only? For instance, I'd like to run an animation first and then have a different website or content load afterwards fo ...

Hide or eliminate SVG element

Can CSS or jQuery be used to remove or hide an SVG element? I am familiar with modifying div elements using CSS. For example: div[style="position: absolute; cursor: pointer; width: 207px; height: 95px; left: 513px; top: 0px; -webkit-transform-origin: ...

How can PHP be utilized to dynamically add classes to <li> elements and alternate them after every third item

I'm trying to find a way to add a class to an unordered list and alternate that class after every third item. Here's the code I have so far: <?php $i=1; foreach($this->items as $item) : ?> <li class="<?php if ($i % 3 == 0) : ...

Is it necessary to have uniform spacing between links in a responsive navigation menu?

I am attempting to create a horizontal menu navigation system. I have multiple links in the navigation, and my goal is to evenly space them horizontally. Is there a way to achieve uniform spacing between links in a horizontal menu? HTML: <div id= ...

What steps should be taken to position the Header and search bar in the middle of the screen?

How can I center the title and search bar on a website using Bootstrap? I've tried adding my-auto, but it doesn't work. Any suggestions?https://i.sstatic.net/3uuhT.png <!DOCTYPE html> <html lang="en"> <head> < ...