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
michaelotis
Front End Web Development Techdegree Student 20,440 PointsResponsive images using media Queries
I am trying to duplicate the responsiveness of the images in this website. http://alistapart.com/d/responsive-web-design/ex/ex-site-FINAL.html
I can get all the images on 1 line, but then when the window is resized in the browser I can't get the images to grow, then shrink. Here is my code.
<html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>A Flexible Grid</title> <link rel="stylesheet" href="flexible-media-queries.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <body>
<div id="page"> <div class="inner"> <div class="mast"> <h1 id="logo"><a href="#"><img src="logo.png" alt="The Baker Street Inquirer" /></a></h1>
<ul class="nav">
<li class="first"><a href="#"><i>The</i> Weblogue</a></li>
<li><a href="#"><i>Back</i> Issues</a></li>
<li class="last"><a href="#"><i>About</i> Our Paper</a></li>
</ul><!-- /end .nav -->
</div><!-- /end .mast -->
<div class="section intro">
<div>
<h2>“Give me problems, give me <em>work</em>.”</h2>
<p>In the year 1878 I took my degree of Doctor of Medicine of the University of London, and proceeded to Netley to go through the course prescribed for surgeons in the army. Having completed my studies there, I was duly attached to the Fifth Northumberland Fusiliers as Assistant Surgeon. The regiment was stationed in India at the time, and before I could join it, the second Afghan war had broken out. On landing at Bombay, I learned that my corps had advanced through the passes, and was already deep in the enemy’s country.</p>
</div>
</div><!-- /end .section.intro -->
<div class="section main">
<h2><b>Victors <abbr class="amp" title="And">&</abbr> Villains</b></h2>
<ol>
<li id="f-holmes" class="figure">
<a href="#">
<img src="f-holmes.jpg" alt="" />
<span class="figcaption">Sherlock<b> Holmes<b></span>
</a>
</li><!-- /end .figure -->
<li id="f-watson" class="figure">
<a href="#">
<img src="f-watson.jpg"/>
<span class="figcaption"><abbr title="Professor">Dr</abbr> John Hemish <b>Watson</b></span>
</a>
</li><!-- /end .figure -->
<li id="f-mycroft" class="figure">
<a href="#">
<img src="f-mycroft.jpg" alt="mycroft" />
<span class="figcaption">Mycroft <b>Holmes</b></span>
</a>
</li><!-- /end .figure -->
<li id="f-moriarty" class="figure">
<a href="#">
<img src="f-moriarty.jpg" alt="moriarty" />
<span class="figcaption"><abbr title="Professor">Prof</abbr> James <b>Moriarty</b></span>
</a>
</li><!-- /end .figure -->
<li id="f-adler" class="figure">
<a href="#">
<img src="f-adler.jpg" alt="adler" />
<span class="figcaption">Irene <b>Adler</b></span>
</a>
</li><!-- /end .figure -->
<li id="f-winter" class="figure">
<a href="#">
<img src="f-winter.jpg" alt="winter" />
<span class="figcaption">James <b>Winter</b></span>
</a>
</li><!-- /end .figure -->
</ol>
</div><!-- /end .section.main -->
<div class="footer">
<img src="ornament.png" class="ornament">
<p>Illustrations by <a href="http://en.wikipedia.org/wiki/Sidney_Paget">Sidney Paget</a>, words by <a href="http://en.wikipedia.org/wiki/Arthur_Conan_Doyle">Sir Arthur<br>
Conan Doyle</a>.</p>
<p>What remains is by <a href="http://unstoppablerobotninja.com/">Ethan Marcotte</a>.</p>
</div><!-- /end .footer -->
</div><!-- /end .inner -->
</div><!-- /end #page -->
<style>
/This is the imagery at the top of the screen/
.mast{ background-image: url("rag.png"); background-repeat: repeat-x; width: 100%; } /This will be the markup for baker street inquire logo/
logo{
background-image: url("logo-bg.png");
display:block;
background-repeat: no-repeat;
padding-bottom: 220px;
align-content: center;
margin-top: 0;
margin-bottom: 0;
padding-top: 120px;
padding-left: 70px;
}
logo{
margin-left: 108px;
} /This will be the end of the markup for baker street inquire logo/
/*This is the nav section */
.nav li{ display: inline; font: normal 10px Baskerville, Garamond, Palatino, "Palatino Linotype", "Hoefler Text", "Times New Roman", serif; font-size: 1.5em; } .nav li a{ color:#890101; margin-left: 50px; border-bottom: solid gray .1px; padding-left: 40px; padding-right: 30px; padding-top: 5px;
} .nav{ width:60%; margin-left: 360px; margin-top:-348px; margin-bottom: 140px; } /*This is the end of the nav section */
/*This is the section intro section */
.intro{ width:60%; margin-left: 450px; margin-top: -100px; } h2{ text-align: center; } .intro h2{ font: normal 2em "Hoefler Text", "Baskerville old face", Garamond, "Times New Roman", serif; }
.main h2 b{ font-weight: normal; } .amp { font-family: Baskerville, Garamond, Palatino, "Palatino Linotype", "Hoefler Text", "Times New Roman", serif; font-style: italic; font-weight: normal; } /*This is the end of the intro section */
/*This is the picture section */
.main{
border:solid red 2px;
width: 100%;
background-repeat: no-repeat;
background-size: contain;
} .main ol li{ display: inline-block; padding-left: 15px; }
.figure{ width: 100%; height: auto; }
a{ text-decoration: none; }
/*This is the end of the picture section */
body{ background-image: url("bg.png");
}
/*This is the start of the footer section */
.footer{
display: block;
color:#890101;
padding: 40px 0 20px;
font-size: 12px;
text-align: center;
margin-left: 400px;
}
.footer a{ color:#890101; }
.ornament{ font-weight: bold; }
/*This is the end of the footer section */
/*This is the start of the media query section */
@media screen and (max-width: 1299px) { .nav{ margin-top: 100px; width: 100%; } } @media screen and (max-width: 1299px) { .nav li{ display: block; border-top: solid gray 2px; margin-left: -300px; padding-top: 50px;
}
} @media screen and (max-width: 1299px){ .intro{ margin-top: -750px; } .nav{ border: solid red 2px; margin-bottom: -400px; width:5%; } .figure{ border:solid red 2px; width: 248px; height: 259px; border: 1px solid red; background-image: url('f-holmes.jpg'); background-repeat: no-repeat; } }
/*This is the end of the media query section section */
</style> </body> </html>
1 Answer
Robert Tyree
13,335 PointsHi there,
I'm learning myself, but I've had luck using viewport-percentage lengths to grow and shrink with the browser. You might change the image width to something like 16% of the viewport width (vw).
Maybe try something like:
.figure img {
width: 16vw;
}