Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Soufiane Bdaoui
9,602 PointsWhy in css i can't choose a height in percentage for my div.wrap?
I have a simple html page, with only a void div that have the class of "wrap". When i put his height ( with css) in percentage, it just doesn't work. It's like setting it to zero. I tried with ems and px: it works fine. I just don't understand why this div doesn't want to take a percentage measurement for his height, but it accept it in his width.
2 Answers
Dustin Matlock
33,856 PointsHi Soufiane, try setting the parent element's height as well, so it has something to be relative to.
The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to auto. A percentage height on the root element is relative to the initial containing block. —MDN on the CSS Height Property
Joshua Shroy
9,943 PointsTry creating a minimum height first for reference.
Soufiane Bdaoui
9,602 PointsI tried, but still failed ( then i put the parent element in absolute position and it worked). Still thanks for the answer!
Soufiane Bdaoui
9,602 PointsSoufiane Bdaoui
9,602 PointsYa, that worked! thanks!