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

CSS How to Make a Website Styling Web Pages and Navigation Style the Image Captions

Steve Isaacs
Steve Isaacs
2,112 Points

My workspaces site doesn't quite look like the video after this lesson and I can't see why.

When my window is mobile size, the thumbnails are in a grid, but there is an open grid space between thumb 2 and 3. The code seems exactly as it is in the video.

https://www.evernote.com/shard/s3/sh/b539f3a1-72be-4538-91d9-7408efbb77da/a9b029901ab9b2115720679cb799d8a7

Hi Steve,

Do you have the right screenshot?

4 Answers

The reason you see this happening is because your 1st item caption has wrapped to 2 lines making it extend down farther than the 2nd item.

This effectively blocks your 3rd item from floating all the way to the left. Your 3rd item needs to clear the previous floats so that it will be forced down below both the 1st and 2nd items and be able to move all the way to the left.

The problem isn't explained until later on in the responsive part of the course. You may want to briefly jump ahead to this video: http://teamtreehouse.com/library/how-to-make-a-website/responsive-web-design-and-testing/build-a-three-column-layout

You can use nth-child in main.css to fix the 2 column layout problem.

#gallery li {
  float: left;
  width: 45%;
  margin: 2.5%;
  background-color: #f5f5f5;
  color: #bdc3c7;
}

/* Add this */
#gallery li:nth-child(2n + 1) {
  clear: left;
}

This will clear the 1st, 3rd, 5th, 7th,... items or the 1st item in every row on a 2 column layout.

Save the following for when you get to the video linked to above:

When you get to responsive.css you'll end up writing :nth-child(3n +1) to fix the 3 column layout but the earlier one you wrote for the 2 column layout will mess this up and so you have to remove the clear property on those items first.

In responsive.css:

#gallery li:nth-child(2n + 1) {
  clear: none;  /* Sets the clear property back to initial value for the items set in main.css */
}

#gallery li:nth-child(3n + 1) {
  clear: left; /* sets the clear property on the correct items for a 3 column layout */
}

So save the responsive.css somewhere for when you get to that part of the course.

Steve Isaacs
Steve Isaacs
2,112 Points

Oops, sorry - revised link.

Steve Isaacs
Steve Isaacs
2,112 Points

I see that it might be an issue between safari and chrome. When I view in Chrome and shrink to the smallest size, it looks like the video, but safari doesn't allow me to shrink to that size, so I see this intermediate weirdness.

BUT

https://www.evernote.com/shard/s3/sh/91d9885f-62b6-4aaa-84fb-9b92788e3cb9/37ce24f875ac6f717b42dee0687143e5

Now my nav doesn't seem like it has the same padding / margin in the video (I have no idea which, cause this is a blur to me). I wish Treehouse had a link so you could A/B your code with the instructor's, so you could check your code without scrubbing the video.

For this nav problem I think you'll have to post the css in your navigation section. It looks like you're missing top and bottom padding on the ul

Sorry, not the ul but both the nav and the links have padding applied. You might have an error with one of those.

Steve Isaacs
Steve Isaacs
2,112 Points
css /************************
GENERAL
************************/

body {
  font-family: 'Open Sans', sans-serif;
}

#wrapper {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 5%;
}

a {
text-decoration: none;
}

img {
  max-width:100%;
}


/************************
HEADING
************************/

header {
  float: left;
  margin: 0 0 30px 0;
  padding: 5px 0 0 0;
  width: 100%;
}

#logo {
  text-align: center;
  margin: 0;
}

h1 {
  font-family: 'Changa One', sans-serif;
  margin: 15px 0;
  font-size: 1.75em;
  font-weight: normal;
  line-height:0.8em;
}

h2 {
  font-size: 0.75em;
  margin: -5px 0 0;
  font-weight:normal;
}


/************************
NAVIGATION
************************/

nav {
  text-align: center;
  padding: 10px, 0;
  margin: 20px 0 0;
}

nav ul {
  list-style: none;
  margin: 0 10px;
  padding: 0;
}

nav li {
  display: inline-block;
}

nav a {
  font-weight: 800;
  padding: 15px 10px;
}

/************************
FOOTER
************************/

footer {
  font-size: 0.75em;
  text-align: center;
  clear: both;
  padding-top: 50px;
  color: #ccc;
}

.social-icon {
  width: 20px;
  height: 20px;
  margin: 0 5px;
}

/************************
PAGE: PORTFOLIO
************************/

#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: #bdc3c7;
}

/************************
COLORS
************************/

/* site body */
body {
  background-color: #fff;
  color: #999;
}

/* links */
a {
  color: #6ab47b;
}

/* green header */
header {
  background: #6ab47b;
  border-color: #599a68;
}

/* logo text */
h1, h2 {
  color: #fff;
}

/* nav background on mobile */
nav {
  background: #599a68;
}

/* nav link */
nav a, nav a:visited {
  color: #fff;
}

/* selected nav link */
nav a.selected, nav a:hover {
  color: #32673f;
}

It's getting really frustrating in that if there is a problem with my code I have no way to go back and find out whats wrong unless I keep clicking and scrubbing through videos. If you fall off track, it kinda of seems like you're screwed.

Thanks so much for the help, Jason :)

Steve Isaacs
Steve Isaacs
2,112 Points

Jesus, this is just not my day. I tried adding the "backticks" like it said in the markdown link to show code the right way in this comment and even that didn't work.

Steve Isaacs
Steve Isaacs
2,112 Points

Oh I just found the css files for download - never mind about the scrubbing back through videos note. Looking for where i went wrong with my css.

Steve Isaacs
Steve Isaacs
2,112 Points

Just A/B'd my code with the instructor code. Look exactly the same. Discouraged.

You have a comma between your padding values here:

nav {
  text-align: center;
  padding: 10px, 0;  /* Need to remove comma here */
  margin: 20px 0 0;
}

I realize if you're new to this then it's going to be hard to track down your own problems. One thing you can do is download the project files and compare with your code to try to find a difference. That would be easier than trying to find the right spot in a video.

You also have the validators at the w3c which I think you're introduced to later in this course.

html validator: http://validator.w3.org/

css validator: http://jigsaw.w3.org/css-validator/

These will help catch invalid markup you have written as well as syntax errors.

In fact to get some practice you should paste the nav css into the direct input tab of the css validator.

I get the following error:

Value Error : padding , is an incorrect operator : 10px,0

That's telling you the comma you have in there is invalid.

Steve Isaacs
Steve Isaacs
2,112 Points

Thank you!!! - any idea why I can't post correct code in these comments using backticks?

I hadn't seen your 3 comments yet when writing mine so you've already discovered the code.

This thread will help with posting code: https://teamtreehouse.com/forum/posting-code-to-the-forum

Steve Isaacs
Steve Isaacs
2,112 Points

Ok, I'm back on track, all thanks to you Jason. Thanks so very much.