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 trialMartin Ng'ang'a
1,223 PointsAdd css that willl allow alll images to fill their parent element
Some help me remember this....
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: 720px;
max-height: 760px;
}
3 Answers
Laura Cressman
12,548 PointsIn order to make the image fill it's parent element, you want to set the width of the image to the width of the parent element. Since it is unlikely that you will always know the width of the parent element in pixels (plus what happens if it changes?), the easiest way to do this is by expressing width as a percentage. If we want it to take up the entire width of the parent element, then we would use 100% as the max width. In CSS terms:
#img {
max-width: 100%;
}
Matthew Greenberg
8,173 Pointsimg {
max-width: 100%;
max-height: 100%;
}
Martin Ng'ang'a
1,223 PointsAm humbled, Thanks.
Michael Bredthauer
13,429 Pointsimg { height: 100%; width: auto; }
put the image inside of a div element and than you can size the div any way you want.
Martin Ng'ang'a
1,223 PointsThanks a lot.
Michael Bredthauer
13,429 Pointsno prob, I find when I use Sass it makes this kinda thing a lot easier.
Alvin Lin
1,365 PointsAlvin Lin
1,365 PointsIf you set the width and height to 100%, won't it accomplish the same thing? Why max-width?
Martin Ng'ang'a
1,223 PointsMartin Ng'ang'a
1,223 PointsAm glad you helped me, thanks a lot.