Issue with footer not staying at the bottom persists despite changes in resolution

Trying to figure out how to make sure my footer stays at the bottom of the page even when resolution changes. I've attempted changing its position from fixed to relative, but it's not behaving as expected.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png" />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;700&display=swap" rel="stylesheet" />
    <link rel="stylesheet" href="reset.css" />
    <link rel="stylesheet" href="style.css" />
    <title>Frontend Mentor | QR code component</title>
  </head>
  <body>
    <main>
      <article class="card">
        <div class="card__img">
          <img src="https://i.imgur.com/bzXEqJP.png" alt="QR Code redirecting to the Frontend Mentor website" />
        </div>
        <div class="card__content">
          <h1 class="card__title">Improve your front-end skills by building projects</h1>
          <p>Scan the QR code to visit Frontend Mentor and take your coding skills to the next level</p>
        </div>
      </article>
    </main>
    <footer>
      <div class="attribution">
Coded by <a href="">Willson</a>.
      </div>
    </footer>
  </body>
</html>
/*
  1. Use a more-intuitive box-sizing model.
*/
*,
*::before,
*::after {
  box-sizing: border-box;
}
/*
  2. Remove default margin
*/
* {
  margin: 0;
}
/*
  3. Allow percentage-based heights in the application
*/
/* html,
body {
  height: 100%;
} */
/*
  Typographic tweaks!
  4. Add accessible line-height
  5. Improve text rendering
*/
body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
/*
  6. Improve media defaults
*/
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}
/*
  7. Remove built-in form typography styles
*/
input,
button,
textarea,
select {
  font: inherit;
}
/*
  8. Avoid text overflows
*/
p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}
/*
  9. Create a root stacking context
*/
#root,
#__next {
  isolation: isolate;
}
:root {
  --clr-white: hsl(0, 0%, 100%);
  --clr-light-gray: hsl(212, 45%, 89%);
  --clr-grayish-blue: hsl(220, 15%, 55%);
  --clr-dark-blue: hsl(218, 44%, 22%);

  --ff-regular: "Outfit", sans-serif;

  --fs-regular: 0.938rem;

  --fw-regular: 400;
  --fw-bold: 700;
}

/* general styling */

body {
  font-family: var(--ff-regular);
  font-weight: var(--fw-regular);
  font-size: var(--fs-regular);
  color: var(--clr-grayish-blue);
  background-color: var(--clr-light-gray);

  /* specific */
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

/* card styles */

.card {
  --content-padding: 1.25rem;
  --content-spacing: 1rem;

  background-color: var(--clr-white);
  border-radius: 1.25rem;
  overflow: hidden;
  padding: 1rem;
  margin: 1.5rem;
  box-shadow: 0px 10px 15px -3px rgba(0, 0, 0, 0.1);
}

@media (min-width: 600px) {
  .card {
    width: 330px;
  }
}

.card__content {
  text-align: center;
  display: grid;
  padding: var(--content-padding);
  gap: var(--content-spacing);
}

.card__content > h1,
p {
  line-height: 1.25;
}

.card__title {
  font-weight: var(--fw-bold);
  color: var(--clr-dark-blue);
}

.card__img > img {
  border-radius: 0.75rem;
  height: auto;
}

footer {
  width: 100%;
  position: fixed;
  bottom: 0;
}

.attribution {
  font-size: 11px;
  text-align: center;
}
.attribution a {
  color: hsl(228, 45%, 44%);
}

Attempted using absolute positioning instead of fixed, but it didn't yield the desired results. Appreciate any help or advice!

Thanks and enjoy your day!

Answer №1

Utilize the code snippet provided:

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

footer{
    margin-top: auto;
}

Answer №2

Consider this suggestion:
body {
    position: relative;
}
footer {
    position: absolute;
    /*
        Specify the desired placement, such as: bottom: 0;
        Then customize it further according to your needs...
    */
}

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

CSS query: How to eliminate the extra space at the top of a webpage?

How can I eliminate the gray area visible here: The padding in style.css is currently set to: padding: 0; I have attempted to modify this by changing the following: #page { margin-top: 0; } I have tried variations such as: #page { margin-top: 5px !im ...

Using Bootstrap's CSS classes, is it possible to modify the background color of a table cell?

I'm currently working with Bootstrap 5.0 CSS and attempting to create a table with customized cell colors using some of my own CSS styles. The color property seems to be working correctly, but I'm running into an issue with Bootstrap not recogniz ...

Divide the PHP code into separate files

Can someone help me with a coding dilemma I have? I couldn't find any information on Google or this site about it. A friend of mine who has experience in website development and runs his own business uses an interesting system that is new to me. He ...

HTML Files Can Only Interpret Style Attributes Within Elements

UPDATE: Just three days ago, my website looked flawless without any updates to the CSS or HTML. Suddenly, a few days back, I noticed that the styling of my website was completely off. It seemed like the browser decided to ignore my stylesheet and display ...

jquery's each method is not functioning as intended and causing unexpected issues

I'm in the midst of developing a website, and one section requires users to input their details into a form. My goal is as follows: When a user clicks the submit button with any empty fields, I want a span element (initially set to display none in CS ...

What is the best way to center buttons beneath a navbar that has been expanded for small screens using navbar-expand

Here is a picture of my current situation. I am struggling with placing items using bootstrap flexibly, specifically trying to center all the buttons using justify-content: center. However, it seems that the default setting in navbar-expand-sm is justify ...

Leverage Hubspot and Google Analytics to transfer session source and medium data

Is there a way to track session source and medium information in HubSpot to identify where a specific visit originated from before a form is filled out or another conversion event occurs? Ideally, this process would involve transferring the session and me ...

Identifying the HTML Hidden Attribute Using JavaScript Without Dependencies

As someone working in the analytics field, I often rely on CSS selectors to address various issues. Currently, I am faced with a task on a website where I need to determine whether a <p> element is hidden or visible. There are two possible scenarios: ...

Activate video in Slick Slider with the click of a button

I am facing an issue with my slider setup, where each slide contains a video as the background along with play/pause buttons. When I try to play the video by clicking the corresponding button on a specific slide, I encounter this problem: if I click the pl ...

Trigger javascript function with a button click

Is there a way to trigger a JavaScript function from an HTML button that is not functioning properly? REVISED To see the issue in action, please visit this jsfiddle link: http://jsfiddle.net/winresh24/Sq7hg/341/ <button onclick="myFunction()">Try i ...

What steps are involved in converting .html files to .ejs format via terminal?

I'm currently working on a Node project and I have a bunch of HTML files that I need to convert to .ejs format. Does anyone know of a quick way to change all the .html files in my directory to .ejs using terminal commands? ...

How to completely color a div in CSS

<h:head> <title>Unique Title</title> <style> .top{ margin: 0; padding: 0; background-color: blue; height: 15px; width: max-content; } </style ...

Extract the chosen option from a dropdown menu, and then transfer it to another dropdown menu with a new corresponding value

Below is a select box I currently have: <td align="center"> <select id="selectW" name="type" onChange="this.form.submit()"> <option value="select...">select</option> <option value=" ...

display a list of items in the dashboard using Angular 2 md-sidenav when clicked

I've successfully implemented a sidebar navigation menu in Angular 2, resembling the image shown in the link below: https://i.sstatic.net/KFvJQ.jpg UPDATE: However, I'm facing an issue where clicking on a category link within the sidebar doesn ...

Issue: The serializer is receiving more than one value for the 'instance' argument

Recently, I started working with Django My current project involves performing CRUD operations using serializers, but I encountered this particular error: Here is the function in question: def updateemp(request, id): Updateemp = EmpModel.objects.get( ...

When a new page loads, use Javascript to automatically reposition an anchor element below a top fixed element

I am in the process of learning how to use Javascript, and I have some JS code that moves page anchors 90 pixels below the top of the page. This is done to ensure that the contents of the anchor are not hidden by a fixed element at the top of the page. It ...

CSS positional sequencing dilemma

I am having trouble with the layout in this particular scenario: . In the #boxOne div, I have a link followed by a div (#formloc) containing an input and another link. Even though the first link ("Appliquer une localisation") is placed before the #formlo ...

Breaking apart a string and mapping it to specific fields

My issue is relatively straightforward. Upon loading my page, a long string representing an address is generated. For example: 101, Dalmations Avenue, Miami, Florida, USA, 908343 With the help of jQuery, I can split the string using: var address = sel.o ...

Adjusting the appearance of a label within an md-input-container using a CSS class

Looking for a way to apply styling to the md-input label inside md-input-container using ng-class. While able to style with inline css, encountering issues when trying to use a css class on the label. Is this expected behavior or am I overlooking somethin ...

Bootstrap the registration form to center it in the layout

https://i.sstatic.net/IWSHz.png Here is the code snippet: <div class="col-md-4 col-md-offset-3">. I am new to Bootstrap and trying to center a form that is currently on the left. I have experimented with different col-md and col-xl numbers, but have ...