CSS- stick footer to bottom of page (so only visible after scroll) WITHOUT html selector?

skyguy

Alright, Im having CSS problems here. My original question was CSS/html - make footer ONLY visible after scroll? stick to bottom just below visible page area? and I achieved the effect I wanted on ONE page with this html:

<div class="wrapper">
  <h1 class="headertext">Welcome back.</h1>
</div>
<div class="footer">Footer</div>

And CSS:

* {
  margin: 0;
}

html, body {
  height: 100%;
}

.wrapper {
  background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
  min-height: calc(100% + 142px);
  margin-bottom: -142px;
}

.wrapper:after {
  display: block;
  content: "";
  height: 142px;
}

.footer {
  background-color: white;
  opacity: 0.5;
  height: 142px;
  text-align: center;
}

The problem is that the following:

* {
      margin: 0;
    }

    html, body {
      height: 100%;
    }

which allows this to work has screwed up (really screwed up) every other page on my site and furthermore, doesnt have the same effect on the footer on these pages. Im looking for a simpler method of sticking the footer to the absolute bottom (just past the page content) JUST using the class selectors, i.e. no html, body, or *.

Ive tried putting height: 100%andmargin: 0 just in the wrapper and footer since these apply to all, but my footer either remains stuck to top of page or not visible at all.

Here is the CSS Im working with at the moment:

.wrapper:after {

 height: 100%;
  height: 89px;
}

.wrapper {
     margin-bottom: -89px;
    background: #50a3a2;
    background: -webkit-linear-gradient(top left, #50a3a2 0%, #53e3a6 100%);
    background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
    position: absolute;
    margin: 0;
    width: 100%;
    height: 100%;
    min-height: calc(100% + 89px);
    margin-top: 0px;

    z-index: -1;
    text-align: center;
}
.footer{

    position: absolute;
    bottom: 0px;
height: 89px;
    background-color: rgba(255, 255, 255, 0.7);
    opacity: 0.8;
    text-align: center;
    z-index: -3;
    color: white;
}

Is there any way to accomplish this? Again, I don't want a fixed footer, I want it to just regardless of amount of content on page stay stuck just BELOW content. Im desperate here - have a broken site at the moment

Ason

Will this work for you ?

This is fully dynamic solution where the wrapper takes the remaining space left by the footer.

html, body {
  margin: 0;
}
.container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.wrapper {
  background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
  flex: 1;
  padding: 10px;
}
.footer {
  background-color: white;
  opacity: 0.5;
  padding: 10px;
  text-align: center;
}
<div class="container">
  <div class="wrapper">
    <h1 class="headertext">Welcome back.</h1>
  </div>
  <div class="footer">Footer</div>
</div>

If you by no means can use html, body { margin: 0; }, another option is using absolute positioning.

.container {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.wrapper {
  background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
  flex: 1;
  padding: 10px;
}
.footer {
  background-color: white;
  opacity: 0.5;
  padding: 10px;
  text-align: center;
}
<div class="container">
  <div class="wrapper">
    <h1 class="headertext">Welcome back.</h1>
  </div>
  <div class="footer">Footer</div>
</div>

If you can't use flex, use display: table, it has the same dynamic feature for a sticky footer though you need an extra wrapper as a row

html,
body {
  margin: 0;
}
.container {
  min-height: 100vh;
  display: table;
  width: 100%;
}
.row {
  display: table-row;
  height: 100%;
}
.row ~ .row {
  height: 1px;
}
.wrapper {
  display: table-cell;
  background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
  padding: 10px;
}
.footer {
  display: table-cell;
  background-color: white;
  opacity: 0.5;
  padding: 10px;
  text-align: center;
}
<div class="container">
  <div class="row">
    <div class="wrapper">
      <h1 class="headertext">Welcome back.</h1>
    </div>
  </div>
  <div class="row">
    <div class="footer">Footer</div>
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Making the footer stick at the bottom of the page

From Dev

Stick a footer to bottom - without jQuery

From Dev

css - footer wont stick at the bottom

From Dev

Footer on html pages that stick dynamically at the bottom

From Dev

HTML CSS Footer at the bottom

From Dev

Footer refuses to stick at the bottom

From Dev

stick footer to the bottom

From Dev

Footer does not stick to the bottom

From Dev

Footer always stick to the bottom

From Dev

Extend div to bottom of page (only HTML and CSS)

From Dev

Bootstrap Web Template: How to stick the footer element to the bottom of the page?

From Dev

Make site footer stick to bottom of the page or below content depending on the height?

From Dev

Scroll to the Bottom of the Page after postBack

From Dev

HTML & CSS - Text stick to bottom of div?

From Dev

place footer at bottom only if page is "short"

From Dev

Set Footer To Bottom Of Page Using JavaScript only

From Dev

Unable to make footer stick to bottom

From Dev

Sticky Footer not fully stick on the bottom

From Dev

How to make the footer stick to the bottom?

From Dev

Stick footer to bottom of wrapper, and get page to fit the whole space between nav & footer

From Dev

Stick footer to bottom of wrapper, and get page to fit the whole space between nav & footer

From Dev

CSS footer at bottom of FORM, not body/page

From Dev

CSS: how to attach footer to the bottom of the page

From Dev

Sticking HTML 5 table footer at bottom of the page

From Dev

HTML - Position Page Footer Based on Scroll

From Dev

Maintaining scroll position within page after CSS event without JS?

From Dev

CSS - hidden div at bottom of the page but visible header

From Dev

CSS - hidden div at bottom of the page but visible header

From Dev

Scroll to bottom of page after get request AngularJs

Related Related

  1. 1

    Making the footer stick at the bottom of the page

  2. 2

    Stick a footer to bottom - without jQuery

  3. 3

    css - footer wont stick at the bottom

  4. 4

    Footer on html pages that stick dynamically at the bottom

  5. 5

    HTML CSS Footer at the bottom

  6. 6

    Footer refuses to stick at the bottom

  7. 7

    stick footer to the bottom

  8. 8

    Footer does not stick to the bottom

  9. 9

    Footer always stick to the bottom

  10. 10

    Extend div to bottom of page (only HTML and CSS)

  11. 11

    Bootstrap Web Template: How to stick the footer element to the bottom of the page?

  12. 12

    Make site footer stick to bottom of the page or below content depending on the height?

  13. 13

    Scroll to the Bottom of the Page after postBack

  14. 14

    HTML & CSS - Text stick to bottom of div?

  15. 15

    place footer at bottom only if page is "short"

  16. 16

    Set Footer To Bottom Of Page Using JavaScript only

  17. 17

    Unable to make footer stick to bottom

  18. 18

    Sticky Footer not fully stick on the bottom

  19. 19

    How to make the footer stick to the bottom?

  20. 20

    Stick footer to bottom of wrapper, and get page to fit the whole space between nav & footer

  21. 21

    Stick footer to bottom of wrapper, and get page to fit the whole space between nav & footer

  22. 22

    CSS footer at bottom of FORM, not body/page

  23. 23

    CSS: how to attach footer to the bottom of the page

  24. 24

    Sticking HTML 5 table footer at bottom of the page

  25. 25

    HTML - Position Page Footer Based on Scroll

  26. 26

    Maintaining scroll position within page after CSS event without JS?

  27. 27

    CSS - hidden div at bottom of the page but visible header

  28. 28

    CSS - hidden div at bottom of the page but visible header

  29. 29

    Scroll to bottom of page after get request AngularJs

HotTag

Archive