How to stretch an element to the end of the screen?

Asked

Viewed 884 times

0

How to stretch an element to the bottom of the page taking into account the position it is in?

ex:

 <div class="caixa1">CAIXA 1</div>
 <div class="caixa2">CAIXA 2</div>

.caixa1{background-color: red;}
.caixa2{background-color: blue;}

How to make the box extend to the end of the screen?

Note that I am not looking for an example footer!

Preferably without use of javascript

2 answers

1

In any of the solutions you are having overflow of the div on the page, ideally you calculate the height of it, this way:

height: calc (100% - a); 

Where a is the distance of the object to the top of the page, I believe that only with js we can take this value dynamically, this way it is better to insert manually.

  • If I’m not mistaken Calc() is a css 3 resource

-1


  • Thanks for the help, but your example goes beyond the screen limit.

  • I adapted your example, and it seems that it worked, just a small adjustment adding overflow:hidden and height:100% in the body

  • Yes, normally this should already be done when starting a new project, but yes you are right :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.