The issue of the footer kicking out of place in the HTML layout was successfully resolved after

I am in the process of creating a simple footer that will always stay at the bottom of the page. The content on the page will not exceed the screen size, eliminating the need for scrolling. (There are a total of 5 HTML pages, and I want the footer and header to remain consistent across all of them.)

However, when I set the footer to be "fixed", upon inspecting the page in Chrome, it seems like the footer is no longer considered part of the body or HTML layout.

I have managed to display the footer on the screen by adjusting its width to 65% and centering it using a wrapper. However, I believe the footer should become highlighted when pointing to the body and HTML elements during inspection.

Any insights into why this might be happening? It appears to be related to changing the position of the footer to fixed.

Below is the HTML and relevant CSS code:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="stylesheet" href="../normalize.css">
  <link rel="stylesheet" href="index-styles.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" 
  integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">
  <title>Play2Learn Home Page</title>
</head>
<body>
    <header>
      <h1>Play2Learn Logo</h1>
        <nav>
            <ul>
                <li><a class="border" href="index.html">Home</a></li> 
                <li id="games-li"><a class="border" href="#">Games</a> 
                    <ul id="games-ul">
                        <li><a href="games/anagram-hunt.html">Anagram Hunt </a></li>
                        <li><a href="games/math-facts.html">Math Facts Practice</a></li>
                    </ul>
                </li>
                <li><a class="border" href="about.html">About</a></li> 
                <li><a href="login.html">Login </a></li> 
            </ul>
        </nav>
    </header>
<main>
    <div id="testimonial">Happy Clients Say...</div>
    <div id="quote">"I never have more fun than when I'm playing Anagram Hunt. It's the best game I've ever played!"</div>
    <div id="author">-Justin Jest</div>
    <section id="grids">
        <div id="grid1">
            <h3 class="article-title">Anagram Hunt</h3>
                <article id="article1">Lorem ipsum dolor 
                    sit amet, consectetur adipiscing elit. 
                    Cura bitur tristique odio ac sem congue luctus.
                    Praesent vel rutrum lectus.
                    Nam mattis finibus odio. Suspendisse ligula orci, 
                    ullamcorper vitae nulla nec, tempor auctor felis. 
                    Sed eu luctus sem.
                </article>
            <a href="games/anagram-hunt.html" title="Play Anagram Hunt"><button>Play</button></a>
        </div>
        <div id="grid2">
            <h3 class="article-title">Math Facts Practice</h3>
                <article id="article2">Lorem ipsum dolor 
                    sit amet, consectetur adipiscing elit. 
                    Cura bitur tristique odio ac sem congue luctus.
                    Praesent vel rutrum lectus.
                    Nam mattis finibus odio. Suspendisse ligula orci, 
                    ullamcorper vitae nulla nec, tempor auctor felis. 
                    Sed eu luctus sem.
                </article>
            <a href="games/math-facts.html" title="Play Math Facts Practice"><button>Play</button></a>
        </div>
    </section>
</main>
    <footer>
    &#169 2021 Play2Learn
    <a href="contact-us.html" title="Contact Us"><i class="fas fa-envelope-square"></i></a>
        <a href="https://instagram.com" title="Instagram"><i class="fab fa-instagram-square"></i></a>
        <a href="https://twitter.com" title="Twitter"><i class="fab fa-twitter-square"></i></a>
        <a href="https://facebook.com" title="Facebook"><i class="fab fa-facebook-square"></i></a>
    </footer>
</body>
</html>

<footer {
    border-top: 2px solid black;
    width: 100%;
    height: 60px;
    font-size: 12px;
    padding-top: 0.5rem;
    bottom: 0;
    position: fixed;
}
    
footer a {
     color: inherit;
     font-size: 46px;
     padding-left: 1rem;
 }

Answer №1

Have you checked out this useful resource:

Your code has been seamlessly integrated with it:

html,body {
  margin:0;
  padding:0;
  height:100%
}

#container {
  margin-left:0.5em;
  min-height:100%;
  position:relative;
}

header {
  padding:0.1px;
}
  
main {
  padding-bottom:60px;  /* Height of the footer */
}
  
footer {
  border-top: 2px solid black;
  width: 100%;
  font-size: 12px;
  padding-top: 0.5rem;
  bottom:0;
  position:absolute;
}

 footer a {
   color: inherit;
   font-size: 46px;
   padding-left: 1rem;
 }
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="stylesheet" href="../normalize.css">
  <link rel="stylesheet" href="index-styles.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" 
  integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">
  <title>Play2Learn Home Page</title>
</head>
<body>
<div id="container">
    <header>
      <h1>Play2Learn Logo</h1>
        <nav>
            <ul>
                <li><a class="border" href="index.html">Home</a></li> 
                <li id="games-li"><a class="border" href="#">Games</a> 
                    <ul id="games-ul">
                        <li><a href="games/anagram-hunt.html">Anagram Hunt </a></li>
                        <li><a href="games/math-facts.html">Math Facts Practice</a></li>
                    </ul>
                </li>
                <li><a class="border" href="about.html">About</a></li> 
                <li><a href="login.html">Login </a></li> 
            </ul>
        </nav>
    </header>
<main>
    <div id="testimonial">Happy Clients Say...</div>
    <div id="quote">"I never have more fun than when I'm playing Anagram Hunt. It's the best game I've ever played!"</div>
    <div id="author">-Justin Jest</div>
    <section id="grids">
        <div id="grid1">
            <h3 class="article-title">Anagram Hunt</h3>
                <article id="article1">Lorem ipsum dolor 
                    sit amet, consectetur adipiscing elit. 
                    Cura bitur tristique odio ac sem congue luctus.
                    Praesent vel rutrum lectus.
                    Nam mattis finibus odio. Suspendisse ligula orci, 
                    ullamcorper vitae nulla nec, tempor auctor felis. 
                    Sed eu luctus sem.
                </article>
            <a href="games/anagram-hunt.html" title="Play Anagram Hunt"><button>Play</button></a>
        </div>
        <div id="grid2">
            <h3 class="article-title">Math Facts Practice</h3>
                <article id="article2">Lorem ipsum dolor 
                    sit amet, consectetur adipiscing elit. 
                    Cura bitur tristique odio ac sem congue luctus.
                    Praesent vel rutrum lectus.
                    Nam mattis finibus odio. Suspendisse ligula orci, 
                    ullamcorper vitae nulla nec, tempor auctor felis. 
                    Sed eu luctus sem.
                </article>
            <a href="games/math-facts.html" title="Play Math Facts Practice"><button>Play</button></a>
        </div>
    </section>
</main>
    <footer>
    &#169 2021 Play2Learn
    <a href="contact-us.html" title="Contact Us"><i class="fas fa-envelope-square"></i></a>
        <a href="https://instagram.com" title="Instagram"><i class="fab fa-instagram-square"></i></a>
        <a href="https://twitter.com" title="Twitter"><i class="fab fa-twitter-square"></i></a>
        <a href="https://facebook.com" title="Facebook"><i class="fab fa-facebook-square"></i></a>
    </footer>
    </div>
</body>
</html>

(Take note that the footer height is defined in the padding-bottom for main.)

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

Looking to access a variable in Python Flask before it is referenced

I encountered an issue while trying to reference the variable "found_user," an object of the User class; it is defined within an if statement when a user logs in to the home page for the first time. My intention is to utilize the user's id to generate ...

Is there a way to pause the slideshow? Are there any ways I can enhance the code to make it more efficient?

Currently, I am testing a slideshow that automatically transitions every 1 second. I have set it up to pause when it reaches the first image. However, when it stops on the initial image and I click the next button, nothing happens. If I try to interact wit ...

Web Development: Custom Search Form

I am looking to create a website with a form similar to this one, but I'm struggling to figure out how to incorporate all three components into a single form using only HTML and CSS - no javascript. Do you have any suggestions or advice on how to achi ...

Is it possible to drag and drop without using jQuery UI?

Currently, I'm developing a jquery plugin that incorporates drag and drop functionalities using HTML5 drag attributes. The functionality is working well, except for one issue - linking the function names to their designated targets. Although the func ...

Is it possible to incorporate shadows on a pie chart using recharts?

Does anyone know how to enhance a pie chart with shadows using the recharts library? https://i.sstatic.net/JLGVF.png https://i.sstatic.net/f5qv4.png If you have any solutions, please share. Thank you! ...

stop an html page from opening a new window

When using my HTML-based application, there are instances when it needs to open another URL within an iframe. However, a problem arises when the third-party URL within the iframe also opens a new window with the same content and URL. How can I prevent th ...

I am facing an issue where new tags are not being created when I pre-fill values in the tags input field on Bootstrap

When working on the Product Edit Page, I successfully displayed the old data that was selected previously. However, I am facing an issue with adding new tags. The new tags do not appear when I press enter or space after typing in the input field. It is pos ...

JavaScript-generated div not recognizing CSS in Internet Explorer

Once again, dealing with Internet Explorer has become a major headache. On headset.no, we have incorporated a small blue search field. However, when you input "jabra" into the field, it should generate suggestions in a div underneath. This feature operates ...

Bring to life the div that has been clicked

There are three divs labeled as "left", "active", and "right" in my setup: Whenever the left div is clicked, it animates to become active and the previously active one moves into its place. I want this same functionality to apply to the right div as well. ...

HTML header with zero margin

Hi there! I am currently learning the basics of HTML and CSS. I have a question regarding creating a header with no margins on the edges. Any advice would be greatly appreciated as I haven't been able to find a clear solution. Below is my code snippet ...

Other options for positioning background in SVG or using CSS within SVG could include center center alignment settings

I am currently developing a website where I have a div covered by an SVG. When I use this SVG as a background image and apply background-position: center center, it functions as expected. However, my issue arises when I try to add additional CSS in this ma ...

Choose everything except for the list and its heading

I have a portion of HTML code on my hands. <div class="ProductDescriptionContainer"> <p>This handsome Clergy Shirt has a trim low neckband with two reinforced buttonholes, one at the front, one at the back, to align with Ziegler's Collare ...

Unable to show additional columns beyond 6 while using Bootstrap's row-cols feature

Currently working on developing an auction website where I plan to showcase the listings as cards in columns. I have successfully managed to display a varying number of cards on different screen sizes, but I am facing an issue with showing more than 6 card ...

What is the best way to update specific content with fresh URLs?

I am interested in keeping certain sections of my page static, such as the header and footer, while allowing the main content to change dynamically. Additionally, I would like the URL to update based on the new content being displayed. Although I am famil ...

How to bypass validation for required input in jQuery validate plugin

As an example, consider the <input name="surname" id="surname" type="text">. Sometimes I want to hide this input and make it non-required. My current workaround is to set a value such as "some value" when hiding the input, and then remove this value ...

Disappearing Cloned Form Fields in jQuery

Hey there! I'm trying to duplicate a section of a form using the code below. But for some reason, the copied fields are only visible for a split-second before they disappear. Can anyone spot any errors that might be causing this strange behavior? jQu ...

Connect an EventListener in JavaScript to update the currentTime of an HTML5 media element

*update I have made some changes to my code and it is now working. Here's the link: I am trying to pass a JavaScript variable to an HTML link... You can find my original question here: HTML5 video get currentTime not working with media events javscr ...

Having trouble with getting the second JavaScript function to function properly?

I am facing an issue with the second JavaScript function. When I click the 'Send Mail' button, it should call the second function and pass it two values. However, the href line (second last line in the first function) is not rendering correctly. ...

Execute PHP script through jQuery request within the context of a Wordpress environment

I want to replicate a specific functionality in WordPress. In this functionality, jQuery calls a PHP file that queries a MySQL table and returns the result encapsulated within an HTML tag. How can I achieve this? <html> <head> <script ...

Convert a web page with embedded images using Base64 strings into a PDF file using JavaScript

My website has numerous images with base 64 string sources. Typically, I am able to download the HTML page as a PDF using a service method that involves sending the HTML page with a JSON object and receiving the PDF in return. However, when there are many ...