Ensure the footer is always displayed at the bottom of the page without obstructing any content when

My goal is to keep the footer stuck at the bottom of the page. I initially tried using bottom:0px; and setting position:fixed;, but this caused issues when resizing the window as it hid other content (I want it to always stay at the bottom):

view image description here

I then attempted to use position:static;, but this resulted in a change in height:

view image description here

See below for the code snippet:

footer {
    font-size: 14px;
    color: gray;
    border-top: 1px solid #2672fb;
    bottom: 0px;
    width: 100%;
    height: 2.5rem;
   position:static;
}
<body>
<div>
...
</div>
<footer>
  <p>Lorem ipsum dolor ...</p>
</footer>
</body>

Answer №1

Within the layout, there was a specific container that enclosed everything except for the footer. This container had a negative margin set to the exact height of the footer. !-- begin snippet: js hide: false console: true babel: false -->

html, body {
  height: 100%;
  margin: 0;
}
.wrapper {
  min-height: 100%;

  /* Set to match footer height */
  /* Taking into account possible margin-bottom of last child element as well */
  margin-bottom: -50px;
}
.footer,
.push {
   width:100%;
   height:100px;
}
.footer{
background-color:yellow;}

<!-- language: lang-html -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <body>
    <button id="add">Add Data</button>
      <div class="wrapper">
        <div class="push"> 
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sem nec lectus fermentum volutpat sed at est. Phasellus ultrices eget mi in congue. Cras condimentum ligula ut metus tempus, eu ullamcorper massa convallis.</p>
<p>Sed non purus et justo pretium lobortis. Mauris euismod arcu ac ex tincidunt interdum. Curabitur placerat eleifend lacus, quis feugiat eros venenatis id. Duis id bibendum velit.</p>
<p>Vivamus rutrum rhoncus velit, vel posuere felis faucibus vel. Ut ornare euismod pellentesque. Nam ac enim fermentum, fermentum nisi vitae, venenatis orci.</p>
<p>Aliquam erat volutpat. Etiam molestie dictum libero a gravida. Donec consequat ante at odio dapibus varius. Fusce malesuada ipsum vel tortor iaculis laoreet.</p>    
    </div>
      </div>
      <footer class="footer"></footer>
    </body>

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

Bootstrap allows for placing three radio buttons in each row within an ASP radio button list

Is it possible to display three radio buttons from the asp:RadioButtonList rblbase in one row, similar to the code below? <div class="row"> <div class="col-sm-4"> Radio1 </div> <div class="col-sm-4"> Radio2 </div> &l ...

The video keeps shifting out of the second column in the row within the bootstrap layout

I'm having trouble positioning a video within a row on my webpage. I want the video to display as the second column in the row, aligning to the right of the page. However, it keeps appearing below the first column as if it's in a separate row. H ...

Ways to Design ASP.NET Buttons for Users with Disabilities

Recently, I attempted to style an asp button using CSS. The Button HTML: <asp:Button ID="btnClockin" runat="server" Text="Clock In" class="FullWidthButton" /> Here is the CSS code: .FullWidthButton {width:100%;} Everything was working fine until ...

Button with embedded Bootstrap dropdown

I need help with centering a dropdown menu on my webpage. I followed the instructions, but it's still appearing next to the button instead of in the center. Below is the code snippet: <div class="btn-group"> <button type=" ...

Aligning the stars with CSS

One of the components I have deals with a star rating system, and I thought it would be cool to use Font Awesome icons for half stars. Everything is working well except for the CSS styling aspect. While I managed to position some of the stars correctly by ...

Designing the child table layout using grid grouping in ExtJS4

I have customized my Extjs4 grid grouping implementation to hide the expand-collapse sign and prevent group header expansion for empty groups. However, I am facing an issue where a white 1px border is being created due to the following CSS class: .x-grid- ...

What is the best way to enable editing of a form when the edit button is clicked?

I have created a simple profile page where users can edit their profile information. I have placed a button at the end of the page. Initially, the form should be uneditable, but when the button is clicked, the form becomes editable. I attempted to use `dis ...

Positioning a bootstrap badge flawlessly inside a block of text

The issue arises when adding a badge in the image below, as there seems to be more space above the badge than below it. Even though the Bootstrap 4 code is clean and untouched, it doesn't work seamlessly. Despite my attempts to adjust margins and line ...

Having trouble loading CSS and JavaScript files in CodeIgniter version 3.0.4?

I am facing an issue with loading my CSS and JS files in the view file. I have already added them to the folder and set the base URL. These codes were working fine with a project I previously did on an older version of CodeIgniter. What could be causing ...

What is the proper way to incorporate this jQuery slider plugin into my website?

I've successfully implemented the HTML and CSS, but I'm struggling with inserting the jQuery and plugin correctly. My familiarity with jQuery and JavaScript is limited, so I think I might be placing them in the wrong location, creating confusion ...

Picking an item for alignment at the center with flexbox styling

What was the reason for specifying .footer-background to have a display: flex property in order to center the .copyright-text? Why did setting display: flex on .footer not achieve the desired result? .footer-background { background-color: #00008B; ...

Is there a way to modify the CSS display property upon clicking a link or button?

I have a ul with the id of "menu-list". The display property is set to "none" in my CSS file, but I want it to switch to "flex" when a link is clicked. I am trying to use the click event on the link to change the display prop ...

Utilize JavaScript to randomly choose images as background tiles in HTML

Currently, I am in the process of developing a game using HTML/CSS/JavaScript. My background is currently set to a single image (100px / 100px) being repeated vertically and horizontally to tile across the entire page body; CSS: body { background-ima ...

Implementing text wrapping within input elements for optimal print.css layout

Can you help me with a print.css issue I'm experiencing? I am currently working on my print stylesheet and I've encountered a challenge where I need to word wrap input fields to ensure all the text is displayed correctly. Despite trying various ...

What could be the reason behind my table appearing all crammed up in a single

My table is appearing in a single cell, and I can't figure out what's wrong. Can someone please take a look and let me know where I messed up? <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" cont ...

Design your website with CSS by incorporating hanging ::before labels that feature unique formatting

I am looking to create labels that designate specific groups of words. Here are the criteria: The label should appear to the left of the word group The words should be enclosed in lines, while the label should not The words should be indented, while the ...

Exploring the Beauty of Trees through Twitter Bootstrap

I've been exploring the creation of a tree structure (similar to a directory tree) using mainly CSS and minimal JS for things like states. I'm wondering if there are any reliable tree plugins available that work well with bootstrap or jquery-ui b ...

Angular 11 component encountering issues with accessing server-side data

Recently, I encountered an issue when trying to connect the PHP API with the Angular service to retrieve data from the database. I am uncertain whether the problem lies within the service, the component.ts file, or the HTML section. Therefore, I have share ...

Unusual images emerge following certain elements in this unique gallery

Looking for some advice on my image gallery created using an ordered list. The issue I'm facing is that the images are not all the same size, causing the 4th and 7th images to disrupt the layout. I have come up with a solution by using: ...

"Applying CSS styles to HTML elements through PHP code

Hey there, I need help with some CSS styling for my PHP code. The code below is used to display a name: while ($db_field = mysql_fetch_assoc($result)) { print $db_field['ship_name'] . "<BR>"; I really want to jazz it up with some ...