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 trialRay Foote
982 PointsWhich is the parent element of the img?
Kinda lost. Trying to set the max-width..
a {
text-decoration: none;
}
#wrapper {
max-width: 940px;
margin: 0 auto;
}
#logo {
text-align: center;
margin: 0;
}
h1, h2 {
color: #fff;
}
nav a {
color: #fff;
}
nav a:hover {
color: #32673f;
}
h1 {
font-family: βChanga Oneβ, sans-serif;
font-size: 1.75em;
font-weight: normal;
}
img {
max-width: 940px;
}
2 Answers
Isaac Asante
4,752 PointsLooking at your CSS, I presume that your layout only has a heading (navigation and logo), and then a main element with the ID wrapper (I'm assuming it is a div element), and then a header and an image. If that is the case, then the main element with the wrapper ID would be the image's parent element.
Because your wrapper ID element already has a fixed width in pixel (940px in this case), then I'd recommend setting your image's max width to 100%, if you want your image to take the full space in width of your wrapper ID element, at most. So you'll need to set your max-width for your image like below:
img {
max-width: 100%;
}
If, unconditionally, you want your image to fill the wrapper ID element in width, then you only need the width property. Just as below:
img {
width: 100%;
}
But keep in mind that, because you have not associated a class name or an ID to your image selector in your style sheet, this declaration will affect all img elements on the website the style sheet is linked with.
Ray Foote
982 PointsThanks guys! So, I would use the ID wrapper instead of just the div?
Isaac Asante
4,752 PointsThe ID wrapper is in fact the parent element, so you could only use #wrapper
in your stylesheet, or you could specify div#wrapper
. In this case, it'd be the same thing. That is, if the ID wrapper is indeed associated with a div element.