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
Cameron Bourke
10,198 PointsCSS Bug/Problem!
Hey everyone, I'm stuck on a certain task with css.
The code snippet for the problem is at: http://codepen.io/cambourke/pen/uKcds
Basically I'm trying to get each div to be 100% height. But it does not want to work. What is confusing me is that I know in order to get an element to be 100% high its parent element needs to be also set to 100% high. However, I have set both the html & body to a height of 100% so I don't know why the div elements in the wrapper are not working.
If anyone could work this out that would be great, it should be a little challenging so kudos if you can work it out.
Cheers!
6 Answers
Kevin Kenger
32,834 PointsHey Cameron,
You're right about having to set the parent's element to 100% in order to get the element itself to be 100%. But it looks like you didn't do that for everything you had to. Since the divs that you're targeting are in the the div with the gallery class, you have to add a height: 100%; rule to your gallery selector as well.
Also if you want them to actually span the height of the page, you'll have to remove the margin: 10% 10%; from the gallery selector, because that's pushing your divs inside of it away from the edges of the viewport.
I hope that helps with what you're trying to do!
Kevin Kenger
32,834 PointsHaha yeah that's weird! OK it looks like it has something to do with your .gallery. So you've got divs one, two, and three in one gallery div and four, five, and six in another. If I remove the second gallery div so all six are in the same div, the problem goes away. But is there any reason you had it like that? I don't want you to have to sacrifice something because of it. It's just styling those two exactly the same way since they've got the same class and other than their content are more or less identical, and I'm assuming that's why they're overlapping.
Kevin Kenger
32,834 PointsOK I came up with something that I think could work. It's a little sketchy and could use some tweaking as far as heights and percentages go, but I think it gets the job done. The reason that they're overlapping is because the height of .gallery is 100%. So when you scroll down the page (past 100%), the next gallery div starts. So I made the gallery 300% and each div inside of it 33.333% (roughly 1/3 of 100%). That way the next .gallery div starts after divs one, two, and three.
I just forked your pen here. Let me know if this could work.
Cameron Bourke
10,198 PointsHey Kevin. thats for the response!
I changed the rules you mentioned above you while the divs height are now equalling 100% which is great, some weird things are starting to happen haha. The divs are overlapping themselves and I haven't been able to work out why this is the case. I've updated the code pen if you wanted to check it out.
Cameron Bourke
10,198 PointsI thought that might have something to do with it. The aim with this code is to create three divs (or possibly have an ul with 3 li items) that are placed one under the other. Each div was to have the rule height: 100% so that it would span the height of the viewport. Then a margin of 10% applied to css .gallery which would act as the parent container so effectively the margin gets applied to the three divs are a whole and not individually. The idea being that I could style it in a way that I would be able to copy and paste the gallery div anywhere in the mark up and it still would look the same. I hope that makes sense haha.
Cameron Bourke
10,198 PointsHaha I was actually thinking about doing something with the 300%, although I still had it at 100% height instead of the 33%. That works perfect man, and now I've added that 10% margin to the .gallery which has now separated all three galleries.
http://codepen.io/cambourke/pen/Lbfzo
Cheers for all the help man, really appreciate it!
Kevin Kenger
32,834 PointsAwesome dude, it was my pleasure!