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

HTML How to Make a Website Responsive Web Design and Testing Refactor the Layout

question

I came back to this question and I think there is a glitch because ill do the same thing and sometimes it works and sometimes it won't the first question is Inside the media query, select the list items inside the gallery and add a width of 28.3333%. and it won't work now

5 Answers

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

You'll be using the :nth-child() selector to target your list items. It's a little tricky, but we use the formula (an + b) to determine which elements are selected.

a is your cycle size, so if you want to target every 4th item, a = 4.

n is the counter. You don't need to do anything with it...just leave it as n in your code.

b is your offset. So, for example, if you wanted to start counting from the 3rd element, b = 3. For this exercise, you have no offset, so b=0. When b=0, you can leave it out of your selector.

So, to select every 4th #gallery li, you would set up your selector as follows: #gallery li:nth-child(4n).

To clear the left float, you would use clear: left;, so the whole statement would read #gallery li:nth-child(4n) { clear: left; }.

Now...I'm not sure why your first challenge is passing, because you've added your own media query to the top of the page, but here's the final code that should get you through this part of the challenge (You'll see the new #gallery li:nth-child(4n) selector at the bottom of the code:

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: 100%;
}

#gallery {
  margin: 0;
  padding: 0;
  list-style: none;
}

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

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

nav li {
  display: inline-block;
}

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

.profile-photo {
  display: block;
  margin: 0 auto 30px;
      max-width: 150px;
  border-radius: 100%;
}

.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;
}

@media screen and (min-width: 480px) {
    #gallery li {
   width: 28.3333%; 
  }
  #gallery li:nth-child(4n){
   clear: left;
  }
}

Hope this makes sense!

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

Peter: without seeing your code, the problem's hard to diagnose, but a few other people have had a similar problem with this challenge, so I'll take a shot in the dark. Are you writing a new media query for this challenge? The instructors have already set up the media query at the bottom of the CSS file for you. You'll just need to put your declaration inside this media query...don't create your own.

Hope that helps!

Can anyone help me with this question? They are asking me to clear every 4th list item in the gallery. This is my code, can anyone show me what to do?

'''HTML @media screen and (min-width: 480px) { 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: 100%; }

gallery {

margin: 0; padding: 0; list-style: none; }

gallery li {

float: left; width: 28.3333%; margin: 2.5%; background-color: #f5f5f5; color: #bdc3c7; }

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

nav li { display: inline-block; }

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

.profile-photo { display: block; margin: 0 auto 30px; max-width: 150px; border-radius: 100%; }

.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; }

@media screen and (min-width: 480px) {

} } '''

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

Peter: See my answer above. My hunch was correct...you're creating a media query when they already set one up for you at the bottom of the file.

Move a { text-decoration: none; } to the media query already established at the bottom of the page, delete your media query up top and this should work.

Shawn Flanigan
Shawn Flanigan
Courses Plus Student 15,815 Points

Sorry. Missed part of your question. I'll help you out with the other question in a moment.

thanks, ill be waiting