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
Scott Moore
4,050 PointsImages in CSS
Einsteins theory. Doing the same thing over and over and expecting a different result. Well that's where I am at with this image stuff.
I'm doing some playing around on my own. What I thought I was trying to accomplish was put a basic image in a header in the middle of the header, with text to the left and some icons to the right. so far its working.
Here is what I coded so far.
<div class="img"></div>
.img { background-image: url('img/img.jpg'); display:inline-block; width:100%; height:auto; background-repeat:no-repeat; background-size:contain; border:1px solid black; (put the border on to see what the div would do when resized in the browser.)
What is happening is the image shows up in the middle. When I resize the browser, the image resizes as does the border. Except the border height of the div stays at 100px.
How do I make it so the div resizes with the image? I'm assuming when applying this in a real world application that the div not resizing because its set for 100px would or could mess up a layout for a website.
I have tried changing the height of the div to 100%. But then the image does not show up. It just shows like a pixel. Where I am going wrong in assuming the div would resize and the image not showing up.
Thanks, great site. Learned a lot so far. Lots of knowledgeable people here.
Thanks again for replies.
2 Answers
Sean T. Unwin
28,690 PointsDo you want the height of the div to scale (get narrower) based on width of the browser?
Scott Moore
4,050 PointsHey Sean, I thought the div would have done that already. That's where I am getting confused. The image resizes so does the div. But I'm getting lost as to how I should markup it up so the div and the img resize fluidly. Another words have the div height shrink height wise like the image does. I must be marking it up wrong. Im home form work today so im gonna go back and watch some videos.