1

I made a footer element sticked to the bottom of the page. but, if there is excess elements present in the container. footer element overlaps the container. fiddle link attached here

<div>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        .....
</div>
<footer>
    <h1>Footer Content</h1>
</footer>

Here i have bunch of <p> tags, but footer element overlaps few of the p element.

I don't know what went wrong.

htoniv
  • 1,658
  • 21
  • 40

1 Answers1

1

One way to solve this problem and worked for me right now it is by using flex with direction column and set the footer child align-self: end. Like this, you will guarantee nothing will overlap nothing.

Check this stack question Footer at bottom of page or content, whichever is lower. It will help you understand more.

*,
*:before, 
*:after{
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
body{
   height: 100%;
}

.container{
  display: flex;
  flex-direction: column;
   min-height: 100%;
}

.hello-wrapper{
  padding: 2rem 3rem;
}

footer{
  width: 100%;
  height: 100px;
  background-color: #444;
  color: white;
  padding: 20px;
  text-align: center;
  aligh-self: end;
}
<div class='container'>
<div class="hello-wrapper">
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        <p>Helloworld</p>
        
    </div>
<footer>
    <h1>Footer Content</h1>
</footer>
</div>
DINA TAKLIT
  • 7,074
  • 10
  • 69
  • 74
  • 1
    let me check this @DINA TAKLIT – htoniv Apr 01 '21 at 03:23
  • I will add a new approach that I am trying now and looks that is working. Let me just checking it is a correction of my first answer. – DINA TAKLIT Apr 01 '21 at 03:25
  • It still not working when it has fewer

    tags. i just tried your solution, pls check the fiddle. https://jsfiddle.net/ju9wmky2/

    – htoniv Apr 01 '21 at 03:27
  • footer is not coming to bottom of the page. – htoniv Apr 01 '21 at 03:28
  • I have added a min-height to solve the issuer of few paragraph in the link I have added you will find many versions of solutions – DINA TAKLIT Apr 01 '21 at 03:42
  • the codepen link you shared working in many cases. thanks. – htoniv Apr 01 '21 at 03:52
  • THe flew box answer works if we add min-height for the wrapper in case of lower elements. For the other answers for absolute elements you can check the link I shared in the answer it is very useful. – DINA TAKLIT Apr 01 '21 at 03:53