Sticky Footer CSS-Tricks demo

12 min read

As an AI language model, I do not have the capability to access the internet or view visual content. However, I can provide you with a basic explanation of what a sticky footer is and how it is implemented using CSS.

A sticky footer is a UI design pattern that ensures that the footer of a web page is always visible at the bottom of the viewport, even if the content on the page does not fill up the entire height of the browser window. A sticky footer is typically used on pages where the content has a fixed or minimum height, but the footer should always remain at the bottom of the page, regardless of the amount of content.

To create a sticky footer using CSS, you would typically use the CSS position property. This property allows you to set an element's position in the browser window relative to the viewport or other elements on the page. To make a footer element sticky, you can set its position to "fixed" and its bottom value to 0. This will anchor the footer to the bottom of the viewport and ensure that it remains visible even when the user scrolls through the content.

Here's a basic example of how you could create a sticky footer using CSS:

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

.wrapper {
  min-height: 100%;
  margin-bottom: -50px; /* This is the height of the footer */
}

.content {
  padding: 20px;
  /* The padding should be at least the height of the footer */
}

.footer {
  height: 50px;
  background-color: #ccc;
  position: fixed;
  bottom: 0;
  width: 100%;
}

In this example, we first set the height of the html and body elements to 100% to ensure that the layout always fills the entire viewport. We then create a wrapper element that has a minimum height of 100% and a negative margin that matches the height of the footer element. This effectively pushes the footer element outside of the wrapper and ensures that it remains at the bottom of the page.

The content element has a padding value that allows for enough space between the content and the footer. Finally, the footer element itself has a fixed position and a bottom value of 0, which ensures that it remains fixed at the bottom of the viewport.