CSS
-Tricks
treehouse :
what would you like to learn today?
Web Design
Web Development
iOS Development
Show search box
Search
Search in:
All
Articles
Forums
Snippets
Videos
✕
Home
Forums
Snippets
Gallery
Videos
Almanac
Demos
Lodge
Navigation 'n' Search
Forums
Illustration by Nick Sirotich
Forums
»
CSS Combat
Expanding a div to be the full size of the body
kaashif
Permalink to comment
#
July 2009
Hey,
Got a question about the parallax effect screencast, #9. It's about expanding the div to be the full size of the body.
I realize that divs normally expand to be only as big as necessary to contain their content.
What I don't get is why it's necessary to use the position: absolute; left: 0; top: 0 ... etc trick. Why doesn't height: 100% & width: 100% work?
Thanks
eXo
Permalink to comment
#
July 2009
because you have to declare what 100% is.
put this in your css and it will work
body, html{
width: 100%;
height: 100%;
}
then if you say that a div has to have a height of 100% it knows what 100% is.
Add a Comment
Got a question about the parallax effect screencast, #9. It's about expanding the div to be the full size of the body.
I realize that divs normally expand to be only as big as necessary to contain their content.
What I don't get is why it's necessary to use the position: absolute; left: 0; top: 0 ... etc trick. Why doesn't height: 100% & width: 100% work?
Thanks
put this in your css and it will work
body, html{width: 100%;
height: 100%;
}
then if you say that a div has to have a height of 100% it knows what 100% is.