0

I have googled it but couldn't find any working solution; As a below example the position:absolute does not set the footer at the bottom of page

.footer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  background-color: red;
  color: white;
  text-align: center;
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <div class="footer">
    <p>Footer</p>
  </div>

</body>

</html>

If I scroll it, I will get:

enter image description here

I want the footer get pinned at the bottom of the page, who can I do this?

dariush
  • 3,191
  • 3
  • 24
  • 43

1 Answers1

0

Use position: fixed instead of position: absolute, please check working example below based on your code.

.footer {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background-color: red;
  color: white;
  text-align: center;
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <h2>Fixed/Sticky Footer Example</h2>
  <p>The footer is placed at the bottom of the page.</p>

  <div class="footer">
    <p>Footer</p>
  </div>

</body>

</html>
Girisha C
  • 1,922
  • 1
  • 12
  • 20