The HTML footer elegantly hovers just above the bottom of the page, at specific resolutions

Preparing my website for a college interview, but struggling to figure out why the footer is floating above the bottom of the page when the window size is above a certain point.

Below are the HTML and CSS snippets used:


html,body{
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
    overflow-x: hidden; 
}

body{
    background-color: white;
    color: rgb(85, 85, 85);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.6em;
    margin: 0;
}

.clr{
    clear: both;
}

.container{
    width: 80%;
    margin: auto;
    overflow: hidden;
}

#navbar .container{
    margin: 0;
}

.button{
    background-color: rgb(51, 51, 51);
    color: white;    
}
... (more CSS styles)

Already tried applying position: absolute;, width: 100%;, and bottom: 0; to the footer class, but it obstructed content on the page.

Any assistance would be greatly appreciated.

Answer №1

Have you considered this approach? By adding an extra container with a minimum height, you can ensure that your content fills the available space in the viewport and pushes the footer to the bottom.

To elaborate further, your page consists of 3 main sections:

  • Navigation or Header
  • Content
  • Footer

The goal is to extend the content block to match the height of the screen so that the footer aligns with the bottom edge. You can achieve this by creating a single container for all content sections and applying some CSS to utilize the full available height.

Here's what I did: I created the main-container div and added the following CSS rule:

.main-container: {min-height: calc(100vh - 221px)}

By using the calc() function, you gain better control over the final size. In this case, 221px represents the combined heights of your footer and navbar (you can verify this by inspecting each element). As a result, the .main-container will have a minimum height equal to the total screen height minus the space occupied by the footer and navbar. This ensures that even with minimal content, the footer stays at the bottom edge thanks to the main container utilizing that space efficiently.

html,
body {
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 0px;
  overflow-x: hidden;
}

/*
  Target the element that holds all your content, and set a minimum height so it uses the full viewport height (100vh)
  
*/

.main-content {
  min-height: calc(100vh - 221px)
}

... (CSS code continues here) ... 

... (HTML markup continues here) ...

Answer №2

Have you considered trying out the CSS properties position: relative and bottom: 0 on your element with the id #mainFooter?

By using relative positioning instead of absolute, you may be able to prevent the footer from overlapping other content.

#mainFooter{
    position: relative;
    bottom: 0;
    /* add any other necessary styling properties here */
}

Answer №3

The extra space below the footer occurs when there is unused space on the webpage and no more content to display. To solve this, consider adding more text or images to fill the empty space and ensure that the content occupies the full height of the screen on larger devices.

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 incorporate this PHP script into an HTML document?

Recently, I made the decision to create a booking calendar and integrate it into my website. However, I encountered an issue when trying to include it in the html file. I attempted using the <?php ?> tag, but unfortunately, it did not display as expe ...

Modify the font style of numbers based on the keyboard language selected by the user

Is it possible to change the font family of numbers in input fields based on the user's keyboard language? For example, if the user is typing in Persian, the numbers should be displayed in a Persian font, and when they switch to an English keyboard, t ...

What is the process for designing a menu with animated scaling effects?

I have a design file in PSD format that looks like this. https://i.sstatic.net/R46Ko.jpg My goal is to create a website similar to , where when a user hovers over a link, a circle will appear around it. I am using Bootstrap 4.5 for this project. Here is ...

Using the swiper carousel on WordPress results in an unexpected horizontal scrolling issue

Running an Elementor website, I need to incorporate various image carousels within my post content. Initially, I created a template for each carousel using Elementor. However, I have now decided to switch to utilizing a shortcode that leverages Elementor&a ...

What is the most efficient method for implementing uniform rounded corners in HTML/CSS across different web browsers?

Is there a simple way to achieve cross-browser compatibility without a lot of tedious work? I'm looking for a solution that works effortlessly on IE7+, FF2+, and Chrome, without resorting to using tables which may be outdated. Is there a middle ground ...

Placing pictures one on top of the other as shown in the illustrations

Just joined this community and hoping for some guidance. I'm working on arranging separate images in a specific layout like this. Here's my code on jsfiddle. This is the HTML I'm using: <body> <div class="grid-container" ...

The Dropdown Button Functions Once and Then Stops

I am facing a challenge in implementing a button within an HTML table that triggers a dropdown menu when clicked, and closes upon another click or when the user clicks outside the menu. Oddly, the button only seems to work once before completely losing fun ...

Replace inline formatting with cascading styles

So, I'm currently working with a service provided by DRUPAL that has its own predefined style. I attempted to use CSS with the !important tag to override the existing style, but unfortunately it doesn't seem to be effective. The default style fr ...

The font face feature does not seem to be functioning properly in the IE browser

I'm facing an issue with font face in a jQuery popup. It seems to be working fine on Chrome and Firefox, but it's not rendering properly on IE browsers. Font Face Code in css ---------------------- @font-face { font-family: "pt-sans"; sr ...

Importing data from json into HTML/JavaScript

For a small project, I am working on adding product data to a JSON file and then loading that data into the JavaScript section of my HTML code. However, I keep encountering errors where Microsoft Visual Code indicates that the object I am trying to load is ...

Unlocking the Interactive Potential of CSS Across All Screen Formats

I am currently working on transforming my website into an engaging and interactive platform. My first challenge: The alignment of the logo image does not meet my desired specifications. Whenever the screen width exceeds 1200 pixels, there seems to be exc ...

Tips for formatting div elements to resemble a table layout (see example below in SharePoint)

Is it possible to format a cluster of related divs so they resemble a table as shown in the attached image? Thank you! <div class="collection" <div class="group"> <div class="label">Label1</div> <div class="value"& ...

Utilizing Selenium for the Upload of an APK Document

I've encountered an issue during my test. I'm attempting to upload an APK file, but the process seems to halt at that stage. My attempts with simple sendKeys using the file path and an AutoIT script have both proven unsuccessful. Below is my in ...

Switching the default browser for npm live-server

When I use the npm live-server package to preview my website as it changes, it keeps opening in Edge even though Chrome is set as my default browser on my system. I attempted to use the command suggested on the npm website: live-server --browser=chrome H ...

As the Div descends, it endeavors to maintain alignment with its counterparts

My webpage has a parent div with multiple child divs in one row. These child divs are generated dynamically, so I don't know how many will be displayed at once. The parent div has a fixed width and a horizontal scrollbar appears when all child divs ar ...

Information is not transferring to Bootstrap modal

I attempted to send a value to a modal by following the instructions on the Bootstrap documentation here. However, I am facing an issue where the data is not being successfully passed. To trigger the modal, use the following button: <button type=" ...

Adjust the vertical size and smoothly lower a text input field

When a user clicks on a textarea, I want it to smoothly change height to 60px and slide down in one fluid animation. Check out the JSFiddle example here: http://jsfiddle.net/MgcDU/6399/ HTML: <div class="container"> <div class="well"> ...

How can you find the "et-custom-css" section in WordPress?

One of the challenges I'm facing with my WordPress page is that some CSS classes are located under <style type="text/css" id="et-custom-css">. Additionally, there is a comment at the top of the CSS saying: /* - - - - - - Additional page info - ...

I possess a certain input and am seeking a new and distinct output

I am looking to insert a word into an <input> and see an altered output. For example, Input = Michael Output = From Michael Jordan function modifyOutput() { var inputWord = document.getElementById("inputField").value; var outputText = "print ...

Apply CSS to every other div using a CSS selector

Struggling with selecting specific divs in CSS. Snippet of my code: <div class="card"> <div class="test">Asdasdasd</div> </div> <div class="card"> <div class="test">Asdasdasd</div> </div> <div class= ...