"I can't figure out why my footer keeps showing up at the top of the page unexpectedly

Currently, my footer is showing up at the top of the page but I really want it to be at the bottom. I'm new to HTML so apologies if this is a simple fix.

Here is my file with internal CSS:

.middle {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

body {
  background-image: url("img/background.webp");
  background-size: cover;
  background-position: center center;
}

footer {
  background-color: black;
  color: white;
}
<body>
  <main>
    <a href="example.com" target="_blank" rel="noopener noreferrer"><img src="img/logoanimated.gif" class="middle"></a>
  </main>
  <footer>
    <p>This website is under construction<br>Copyright &copy; 2022 example.</p>
  </footer>
</body>

Answer №1

The element is currently positioned within the .middle class using a fixed position, causing it to appear on top of all other elements. To allow for changes in this behavior, try adjusting the position property to relative or another option aside from fixed.

Answer №2

Utilizing the position attribute allows you to control the placement of elements. In this instance, I employed a fixed position to keep the footer at the bottom, and utilized the inset property for a more concise way of adjusting the top, right, bottom, and left properties. For further information on positions and how to effectively utilize them, refer to this resource.

.middle {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

body {
  background-image: url("img/background.webp");
  background-size: cover;
  background-position: center center;
}

footer {
  background-color: black;
  color: white;
  position: fixed;
  inset: auto 0 0 0;
}
<body>
  <main>
    <a href="example.com" target="_blank" rel="noopener noreferrer"><img src="img/logoanimated.gif" class="middle"></a>
  </main>
  <footer>
    <p>This website is under construction<br>Copyright &copy; 2022 example.</p>
  </footer>
</body>

Answer №3

I adjusted the footer with position: fixed, bottom: 0, left: 0, and width: 100% along with adding some sample background images. I also placed the footer inside a div, resulting in the following design. Hopefully, it meets your requirements.

<!DOCTYPE html>
<html>

<head>
    <title>title</title>
    <style>
        .middle {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        body {
            background-image: url("https://picsum.photos/id/235/200/300");
            background-size: cover;
            background-position: center center;
        }

        .footer {
            background-color: black;
            color: white;
            position: fixed;
            bottom: 0;
            left: 0; 
            width: 100%;
        }
    </style>
</head>

<body>
    
    <a href="example.com" target="_blank" rel="noopener noreferrer"><img src="https://picsum.photos/200/300.jpg"
                class="middle"></a>
  
    <div class="footer">
        <p> This website is under construction<br>Copyright &copy; 2022 example.</p>
    </div>
</body>

</html>

Answer №4

Give this code a try - I have removed all the CSS from the .middle class, which will center the image and position the footer beneath it. It's important to note that using a fixed position for the footer may not be ideal as it will always stay at the bottom of the page. Consider making it static.

Upon reviewing your code, I noticed that the footer was overlapping everything because you set the image to a fixed position, causing content to flow underneath it. Think of the fixed position like two stacked boxes where sliding the bottom one away causes the top one to fall in its place. The bottom box with a fixed position stays in its spot regardless of scrolling, hence why it's called fixed. Remember, adding a fixed position raises the element up while other content flows beneath it.

.middle {
  display: block;
  margin: auto;
}

body {
  background-image: url("img/background.webp");
  background-size: cover;
  background-position: center center;
}

footer {
  background-color: black;
  color: white;
}
<body>
  <main>
    <a href="example.com" target="_blank" rel="noopener noreferrer"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQytQQam75A2ZQMpeZ01oSraB9OHEvBqprjtw&usqp=CAU" class="middle"></a>
  </main>
  <footer>
    <p>This website is under construction<br>Copyright &copy; 2022 example.</p>
  </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

"Reposition all elements contained within a div that have a specific class

I'm completely new to Javascript and I've been trying to move all elements with a specific class inside a particular div. After doing some research, I found a solution that worked using IDs. However, when I tried to adapt it to work with classNam ...

PHP function array_sum returns the sum of all values in an array rather than displaying each number

I have a collection of unique "coupons" with corresponding "productid"s https://i.stack.imgur.com/IgtFN.png My goal is to transform this list into an array using: $claimed = array($rowOrder['productid']); The problem arises when I attempt to ...

Develop a distinctive JavaScript solution that enables an image to appear in fullscreen upon loading the page, and then smoothly fade away after precisely

I have been trying to incorporate a feature on my Shopify frontage website where our logo appears fullscreen and then fades away or disappears after a few seconds, allowing people to access the rest of the website. However, I am facing difficulty in making ...

A step-by-step guide to incorporating expandable and collapsible images within a div element using X

I have successfully created dynamic divs with some data that expand and collapse perfectly. Now I am looking to add expand and collapse images on these divs. I am relatively new to designing in xslt. <xsl:template match="category[key!='org.model.C ...

The range filter is exclusive to the initial controller

My range filter (see code below) is only working on my first controller. I have added the same filter to other controllers in the app.js and HTML, but it's not functioning for some reason. I checked the console for errors, but there are none. Here i ...

Creating responsive images using Bootstrap CSS framework

I have been focusing on optimizing the banner below the navigation menu on this website. My goal is to make it responsive so that the player in the banner remains visible even when scaling down to iPhone size portrait. You can find the code for this secti ...

Struggling to align nested grids in the center

I'm currently following a mobile-first approach in designing my website. The entire website is contained within one main grid, and I also want to include smaller grids that will serve as links to other HTML pages. I created a sample nested grid but am ...

Tips for Resizing google reCAPTCHA

The problem's image is shown below: Below is the code snippet related to the issue: <div class="text-xs-center" id="DIVCATCHA" runat="server"> <asp:HiddenField runat="server" ID="hdnImageSelected" /> <div class="g-recaptcha" data- ...

"Difficulties with Tribute Page Project on FreeCodeCamp: HTML and

I am currently working on a tribute page for a challenge from FCC and I am facing some issues with adding padding to my .life and .work divs in the HTML and CSS code above. Despite spending a few hours searching for solutions online, I have not been able ...

Align your content in the center of any browser

My CSS code is currently only centering on a certain type of screen, but I want it to be centered on any screen. Here is the CSS code: @import url(http://fonts.googleapis.com/css?family=Roboto+Condensed); html{ font-family: "HelveticaNeue-Light" ...

Beginning of my initial endeavor (seeking feedback, general advice, criticism)

Hey everyone! I'm looking for a forum-style platform similar to Stack Overflow where I can get some feedback on my first project. It's the first one I've built from scratch, so I'm open to any critiques or suggestions on what could be i ...

I can't seem to shake off this constant error. Uncaught TypeError: Unable to access property 'classList' of null

I am facing an issue with the "Contact Me" tab as it does not display its content when clicked. Here is the code snippet: <body> <ul class="tabs"> <li data-tab-target="#home" class="active tab">Home< ...

The find element will yield an empty result when using XPath contains with Text() method

When checking for Gender and Date in the assertion, it returns false and the IWebElement displays an empty string. This anomaly only occurs with Gender and Date, while the rest provide accurate results. CODE IWebElement actualname = BrowserHelper.WebDri ...

How to target the following sibling element (not a child) with CSS

I am working with the following HTML structure: <div class="col-sm-12"> <input id="my_id"> <div class="col-sm-1 col-3-box" style="position:absolute; margin-left:340px;"> </div> </div> How can I target and change ...

Ways to implement div on hover in my table's td cells

Here is the HTML table code I have: <table border='1px'> <tr> <td id='td'>first</td> <td>last</td> <tr> <td id='td'>newFirst</td> <td>newSecond</td> </t ...

Position of fixed div set relative to its parent fixed div

I'm facing an unusual situation where I need a fixed div to be positioned relative to its parent, which is also a fixed div. When you take a look at my example, everything will become clear. <div class="drawer"> <p>Drawer</p> & ...

Sliding Image Menu using jQuery

I am struggling with creating a menu using jquery mouseenter / mouseout effects. My goal is to have a small icon displayed that expands to the left and reveals the menu link when a user hovers over it. The issue I am facing is that the effect only works w ...

Troubleshooting techniques for resolving CSS issues with the video.js package in ReactJS

When using video.js in react to build a video player, I encountered an issue with the npm package not providing its inbuilt CSS. How can I add the inbuilt CSS of video.js? Instead of the control bar, I am getting something different than what is shown in t ...

Unveiling concealed content with JQuery

Here is a link to my pen: http://codepen.io/anon/pen/IszKj I am looking to achieve the functionality where clicking on either "any status" or "any date" will reveal a hidden div containing a list of options. My main query is about the best approach to ta ...

Utilize CSS to incorporate special characters as list markers

Is there a way to use CSS to make the list marker in an HTML list display as "►"? ...