Home > Web Front-end > CSS Tutorial > How to Fix a Footer to the Bottom of a Web Page?

How to Fix a Footer to the Bottom of a Web Page?

DDD
Release: 2024-12-16 10:55:17
Original
976 people have browsed it

How to Fix a Footer to the Bottom of a Web Page?

How to Fix Footer to Bottom of Page

Many websites encounter the issue of having a footer that is not fixed to the bottom of the page, especially on pages with a small amount of content. To ensure that the footer remains at the bottom of the page, regardless of the screen size or content length, here is a CSS solution:

#footer {</p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">position: fixed;
height: 50px;
background-color: red;
bottom: 0px;
left: 0px;
right: 0px;
margin-bottom: 0px;
Copy after login

}

This code assigns the following properties to the footer:

  • position: Sets the footer's positioning to fixed, ensuring it remains in place regardless of the page's scroll position.
  • height: Specifies the height of the footer.
  • background-color: Adjusts the background color of the footer for demonstration purposes.
  • bottom: Positions the bottom edge of the footer 0 pixels from the bottom of the page.
  • left: Aligns the left edge of the footer to the left edge of the page.
  • right: Aligns the right edge of the footer to the right edge of the page.
  • margin-bottom: Removes any unwanted bottom margin.

To ensure that the content does not overlap the fixed footer, an additional CSS rule can be applied to the body element:

body {</p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">margin-bottom: 50px;
Copy after login

}

This adds a 50-pixel bottom margin to the body, creating space for the fixed footer to be displayed.

The above is the detailed content of How to Fix a Footer to the Bottom of a Web Page?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Previous article:How Can I Style Elements with CSS Across Different Browsers? Next article:How to Prevent Column Width Expansion in HTML Tables?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template