Sticky footer in Bootstrap causing content to overlap

I'm a beginner when it comes to Bootstrap, and I'm attempting to integrate it with Symfony2. I currently have a sticky top bar in place for navigation purposes. However, I'm facing an issue when I try to add a similar sticky footer at the bottom - it ends up overlapping my content. To resolve the issue with the top navigation bar, I've utilized a JQuery script as shown below:

$(document).ready(function(){
        $(document.body).css('padding-top', $('#topnavbar').height());
        $(window).resize(function(){
            $(document.body).css('padding-top', $('#topnavbar').height());
        });
    });

The structure of my main Twig layout is as follows:

    <div class="navbar navbar-default navbar-fixed-top" id="topnavbar">
      <div class="container-fluid">
      </div>
    </div>
    {% block body %}
    {% endblock %}
    <footer class="footer navbar-fixed-bottom">
    </footer>

I have already tried using original CSS, experimenting with 'margin bottom' and 'padding bottom', but the issue of content overlapping within the {% block body %} persists. I'm at a loss for how to rectify this problem - does anyone have any suggestions?

Answer №1

This topic has not yet been answered.

I am currently working on transferring a theme to Bootstrap, section by section, on a new Bootstrap template.

I have a sticky header and I want the footer to always stay at the bottom. Initially, I had it positioned correctly, but when I checked the responsiveness, the footer started overlapping with the content. I needed to create some space between the content and the footer to avoid this overlap.

Adding margin-bottom to the body tag did not solve the issue, as it only created a gap below the footer. It was logical to expect this behavior from the "body" tag.

The solution was to use "padding-bottom" on the body tag. I set the padding size to 6 pixels more than the height of the footer to ensure sufficient spacing.

body {
    padding-bottom: 120px;
}

.footer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 114px;
}

Remember to adjust the heights according to your design. I hope this tip is helpful!

Answer №2

Introducing a cutting-edge flex-box solution for modern design.

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

main {
  flex: 1;
}
<body>
  <header>Hello</header>
  <main>Here is some amazing content</main>
  <footer>Plus, a sleek sticky footer that won't overlap</footer>
</body>

Answer №3

It's common practice for Bootstrap headers and footers to stick to the top or bottom of the page, sometimes overlapping the main content. To fix footer overlap, you can simply add margin-bottom: [footer height]; to the body, following the customisation example on the Bootstrap site:

sticky-footer.css

body {
  /* Add margin bottom based on footer height */
  margin-bottom: 60px;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  background-color: #f5f5f5;
}

Since you mentioned margin-bottom in your query, if that solution doesn't work, could you share your attempts so far?

P.S. This issue is likely unrelated to Symfony!

Answer №4

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-footer {
  margin-top: auto;
} 

Answer №5

One possible solution is to adjust the height of the container-fluid to auto. I encountered a similar problem and found that this fix resolved it for me as well.

Answer №6

Sharing my solution here as I encountered overlapping footer on my website.

To prevent the footer from overlapping, use Bootstrap 5 and create a sticky footer by placing it within a clearfix tag as outlined in the documentation:

<div class="clearfix">...</div>

https://getbootstrap.com/docs/5.3/helpers/clearfix/

If you're unsure how to make the footer stay at the bottom of the page, apply a flexbox class to the body element like this:

<body class="d-flex flex-column vh-100">...</body>

Next, add flex-grow-1 to the div/section preceding the footer in your template. This will make its box fill the available space and push the footer downwards.

<div class="d-flex flex-grow-1">...</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

What is the best way to pass a CSS root constant to a separate CSS file?

In my Angular test project, I'm experimenting with using the same colors repeatedly. To achieve this, I created a constants.css file where I defined all my root constants, which currently consist of colors. However, I've hit a roadblock when atte ...

Adjust the size of fonts for elements that are added dynamically

My goal is to dynamically add elements with decreasing font sizes to a fixed-width/height container until they no longer fit. I've managed to scale the font based on the browser window size, but that's not the intended solution. Is it possible t ...

Is it achievable to dynamically modify the style URL in an Angular component based on certain conditions?

element: I am working with two different CSS files, one for Arabic layout and one for English layout. I am wondering if it is possible to conditionally change the style URL in the component. Is this feasible? ...

Text positioned in a fixed location

How can I ensure that the main content stays on the right side of the sidebar without adding margin-right? Currently, the sidebar is being covered by the body content due to its fixed position. Is there a solution to prevent this issue? .App { displa ...

Numerous CSS/JS Dropdown Menus

I am seeking the ability to implement a dropdown through CSS in various locations within my HTML prototype. This implies that I require the capability to position multiple dropdowns anywhere on the page. Currently, I utilize this method to generate a sing ...

Enhanced auto-zoom feature with orientation change for iOS 7

My web page was functioning perfectly until the release of iOS 7 by Apple today, causing the layout to break when the screen orientation is changed. When focusing on a text area and rotating the screen to landscape view, the entire page zooms in. However, ...

Challenges with the Placement of Buttons

I am facing an issue with the code below: document.addEventListener("DOMContentLoaded", function(event) { // Select all the read more buttons and hidden contents const readMoreButtons = document.querySelectorAll(".read-more"); const hiddenConten ...

Is there a method to pre-load a CSS background image so that it can still be displayed even without an internet connection?

Situation: Imagine having a web app that shows an error message when trying to perform an action but fails due to a connectivity problem. The error dialogue has a CSS class with a background image that can't load because of the connection issue, res ...

Having difficulties including the Stack Overflow website within an iframe

I've been attempting to embed the Stack OverFlow website into an HTML page using an iFrame, but I'm running into some issues. Oddly, when I tried embedding my other two websites, they displayed correctly, but Stack OverFlow is not showing up on m ...

Issues with Collision Detection between Canvas Rectangles and Balls

I am developing an HTML5 canvas game and encountering an issue with collision detection. The problem occurs when the ball collides with any platform - the ball's gravity should change to -1 and move upwards at the same velocity as the platforms. Howev ...

Load the entire AngularJS webpage using AJAX requests

I'm facing a challenge where I need to integrate an entire legacy page, along with some AngularJS elements, into our new page using AJAX. Initially, all I could see was the raw AngularJS markup: Rank ID {{$index+1}} {{player.playerid}} Afte ...

Setting a CSS style for an ASP.NET button: What you need to know!

I am facing an issue with the styling of my asp:Button. I have applied CSS styles using the cssClass property, but they are not being applied correctly. Surprisingly, when I switch to using asp:LinkButton, the styles work perfectly fine. I prefer not to us ...

The JavaScript function is not functioning properly, whereas another function is working as intended

I have created a HTML form with 2 buttons and a table. Each row in the table consists of a checkbox and 2 text fields. The buttons allow users to add and remove rows from the table. The remove button only applies to rows where their checkbox is checked. T ...

What is the best way to resize a primefaces inputTextArea to match the length of the

I am currently working on improving the appearance of <p:inputTextArea/>. When the page loads, I notice: And when I click on that TextArea: Here is the code: <p:inputTextarea rows="6" value="#{bean.object.value}" style="width: 100%;" /> Is ...

Challenge with adjusting opacity of background when hovering over a box

I've encountered an issue with the background transparency in the following demo. For some reason, it's not working properly. .figure .caption-mask:hover { background: rgba(0, 0, 0, 0.0); } I'm attempting to remove the opacity f ...

I am having difficulty organizing my text into two grid columns and aligning it in the center

.hero { display: grid; grid-template-columns: repeat(2, 33.45rem); grid-template-rows: 12.5rem; border-bottom: .05em solid #05d31f; width: 69.8rem; height: 16.5rem; } .hero-title { grid-row-start: 1; grid-column-start: 1; } .hero-title h ...

I'm encountering difficulties in automatically populating the category field from an API

Hey there! I have set up a signup form and I am trying to automatically fetch categories from the server API to populate an input area. Everything seems to be in place, but for some reason, I am unable to retrieve the data. API: Here is the code I'm ...

Retrieving Information From SVG Files

I have this code snippet saved in a local HTML file: <object id="PriceAdvisorFrame" type="image/svg+xml" data="https://www.kbb.com/Api/3.9.448.0/71071/vehicle/upa/PriceAdvisor/meter.svg?action=Get&amp;intent=buy-used&amp;pricetype=Private Party ...

Exploring the implementation of if/else statements in Sass/HTML

I need assistance with customizing the appearance of a save button on my form. The button is currently disabled and appears in blue color, but I would like it to change to a different color until all fields within the form are completed. Even though it c ...

Align title text to the right within the Material Design Card

I have implemented a Material Design (MDL) card to showcase numeric values in the title. However, I am facing an issue where the values are left aligned by default and I want them to be right aligned. Despite trying various styles, they are being ignored ...