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
Garrett K
Courses Plus Student 1,941 Pointsmy layout keeps breaking when larger than 480px.
I can't seem to figure out why my gallery's layout is breaking when resized to a desktop or laptop resolution. The 4th gallery item drops down to the bottom of the page. When the window is sized below 480px it goes back to two columns and seems to be okay. Are my '#gallery li' element's too wide or something?
Responsive.css:
@media screen and (min-width: 480px) {
/*** contact page ***/
#primary {
width: 50%;
float: left;
}
#secondary {
width: 40%;
float: right;
}
/*** PORTFOLIO PAGE ***/
#gallery li {
width: 28.3333%;
}
/* this is to prevent text from wrapping and breaking the layout, but it's not working!!! */
#gallery li:nth-child(4n) {
clear: left;
}
/*** PROFILE PHOTO PAGE ***/
/*** we can float the profile picture to the left when the page reaches 480px ***/
.profile-photo {
float: left;
margin: 0 5% 80px 0;
}
}
@media screen and (min-width: 660px) {
nav {
background: none; /* text can sit against the header background now since its been removed */
float: right;
font-size: 1.125em;
margin-right: 5%;
text-align: right;
width: 45%;
}
#logo {
float: left;
margin-left: 5%;
text-align: left;
width: 45%;
}
h1 {
font-size: 2.5em;
}
h2 {
font-size: 0.825em;
margin-bottom: 20px;
}
header {
border-bottom: 5px solid #599a68;
margin-bottom: 60px;
}
}
Also here's the CSS from my 'main.css' page:
/* all this code is probably broken or missing semi-colons or has no friends */
/**** GENERAL ****/
body {
background-color: #fff;
color: #999;
font-family: 'Open Sans', sans-serif;
}
a {
text-decoration: none;
color: #6ab47b;
}
#wrapper {
max-width: 940px;
margin: 0 auto;
padding: 0 5%;
}
img {
max-width: 100%;
}
h3 {
margin: 0 0 1em 0;
}
/**** ****/
/**** NAVIGATION ****/
nav {
background: #599a68;
text-align: center;
padding: 10px 0;
margin: 20px 0 0;
}
nav a {
font-weight: 800;
padding: 15px 10px;
}
nav a, nav a:visited {
color: #fff;
}
nav a.selected, nav a:hover {
color: #32673F;
}
nav li {
list-style: none;
margin: 0 10px;
padding: 0;
display: inline-block;
}
/**** ****/
/**** HEADING ****/
header {
background: #6ab47b;
border-color: #599a68;
float: left;
margin: 0 0 30px 0;
padding: 5px 0 0 0;
width: 100%;
}
h1 {
margin: 15px 0;
font-family: 'Oswald', sans-serif;
font-size: 1.75em;
font-weight: normal;
line-height: 0.8em;
color: #fff;
}
h2 {
font-size: 0.75em;
margin: -5px 0 0;
font-weight: normal;
color: #fff;
}
/**** ****/
/**** FOOTER ****/
footer {
font-size: 0.75em;
text-align: center;
padding-top: 50px;
color: #ccc;
clear: both;
}
.social-icon {
width: 20px;
height: 20px;
margin: 0 5px;
}
#logo {
text-align: center;
margin: 0;
}
/**** ****/
/**** GALLERY *****/
#gallery {
margin: 0;
padding: 0;
list-style: none;
}
#gallery li {
float: left;
width: 45%;
margin: 2.5%;
background-color: #f5f5f5;
color: #bdc3c7;
}
#gallery li a p {
margin: 0;
padding: 5%;
font-size: 0.75em;
color: #0B6138;
}
/**** ****/
/**** PAGE: ABOUT ****/
.profile-photo {
display: block;
max-width: 150px;
margin: 0 auto 30px;
border-radius: 100%;
}
/**** ****/
/**** PAGE: CONTACT ****/
.contact-info {
list-style: none;
padding: 0;
margin: 0;
font-size: 0.9em;
}
.contact-info a {
display: block;
min-height: 20px;
background-repeat: no-repeat;
background-size: 20px 20px;
padding: 0 0 0 30px;
margin: 0 0 10px;
}
.contact-info li.phone a {
background-image: url('../img/phone.png');
}
.contact-info li.mail a {
background-image: url('../img/mail.png');
}
.contact-info li.twitter a {
background-image: url('../img/twitter.png');
}
/**** ****/
and last but not least my html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sgt. Hugo Stiglitz | Gun for Hire</title>
<link rel="stylesheet" href="css/normalize.css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700,800|Oswald' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/responsive.css">
<meta name="viewport" content="width=device-width" inital-scale="1.0">
</head>
<body>
<header>
<a href="index.html" id="logo">
<h1>Hugo Stiglitz</h1>
<h2>Gun for Hire</h2>
</a>
<nav>
<ul>
<li><a href="index.html" class="selected">Portfolio</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
<div id="wrapper">
<section>
<ul id="gallery">
<li>
<a href="img/image1.jpg">
<img src="img/image1.jpg" alt="men working in trees">
<p>Men working in trees?</p>
<a/>
</li>
<li>
<a href="img/image2.jpg">
<img src="img/image2.jpg" alt="reading terminal sign">
<p>Reading Terminal is delicious (and expensive).</p>
<a/>
</li>
<li>
<a href="img/image6.jpg">
<img src="img/image6.jpg" alt="flowers">
<p>Just a close-up of some flowers.</p>
<a/>
</li>
<li>
<a href="img/image9.jpg">
<img src="img/image9.jpg" alt="Saleen Mustang">
<p>A nice Ford Mustang.</p>
<a/>
</li>
<li>
<a href="img/image12.jpg">
<img src="img/image12.jpg" alt="forest fire at night time">
<p>Forest fire at night time.</p>
<a/>
</li>
</ul>
</section>
<footer>
<a href="https://twitter.com/garrettk_88">
<img src="img/twitter-wrap.png" alt="twitter logo" class="social-icon">
</a>
<a href="http://www.facebook.com">
<img src="img/facebook-wrap.png" alt="facebook logo" class="social-icon">
</a>
<p>© 2015 Garrett Kravitz.</p>
</footer>
</div>
</body>
</html>
3 Answers
Jonathan Grieve
Treehouse Moderator 91,254 PointsYou might need to check for padding, border and margins on your elements. The element size unless explicitly set with the box-sizing counts for content. padding, border and margin layer of the box model. :-)
. Ali
9,799 PointsHi garette,
Can you be a little more specific about your question as it is a little confusing.
when you say it breaks on desktop resolution what do u exactly mean ?? besides please include ur html and full css .. probably a snapshot of workspace or put it on codepen so we can have a look at it. Cheers
Garrett K
Courses Plus Student 1,941 PointsThanks. I just updated my original post. Here's a screen shot of what's happening as well. Here I am, right as the layout changes from two columns to three.