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

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

Trying to arrange 9 images in an image gallery with 3 rows and 3 columns. Something is not working..

So the first row and third row have images which are 1024 x 682 pixels

The second row has images which are 682 x 1024 pixels. (Ideally all images would be the same size)

I've managed to get the first 7 pictures in the correct position but the last two images are on a 4th column next to each other.

I've written this code which has not solved the problem:

gallery li:nth-child(4n){

clear:both;}

gallery li:nth-child(7n){

clear:both;}

gallery li:nth-child(8n){

clear:both;}

Please can you help?

3 Answers

James Alker
James Alker
8,554 Points

Not sure about your selector though as you just have 'gallery' which is missing an id "#" or class "."

You only need the first 2 nth-child rules you specified, not the '8n' one as that's clearing the 8th element.

If you want to clear every third element (starting from the 4th one) then you can use this :nth-child rule rather than several different rules, try this:

#gallery li:nth-child(3n+4){
    clear: both;
}

It allows you to then add more li elements and you don't need to worry about changing the CSS.

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

Thanks, I left out the '#' accidentally.

Didn't know we could write formulas in there so thanks again. But if you look at my website (in progress) in this link: http://port-80-bz2gnxtxrh.treehouse-app.com/

You'd see the issue still exists with the last 2 images.

Steven Ventimiglia
Steven Ventimiglia
27,371 Points

Do have an example of your page that we can look at?

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

http://port-80-bz2gnxtxrh.treehouse-app.com/

If you view that on a desktop/laptop you can see the issue with the last 2 images.

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

http://port-80-bz2gnxtxrh.treehouse-app.com/

If you view that on a desktop/laptop you can see the issue with the last 2 images.

Steven Ventimiglia
Steven Ventimiglia
27,371 Points

The best idea would be to load your workspace, and then copy and paste the files into Notepad++ or something comparable so you can save it. You can also post the code into JSFiddle.org and I'll fork it and suggest a solution or you can upload it to Google Drive or Dropbox.

Steven Ventimiglia
Steven Ventimiglia
27,371 Points

It says that your Workspace is unavailable. Try again. If you have somewhere to host, upload it there.

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

Hey, I've downloaded Notepad++, do I copy and paste the code from ALL the pages(index.html, about.html, contact.html, main.css and responsive.css) into one page on Notepad++?

And how do I share the code on Notepad++ with you?

Thanks!

Steven Ventimiglia
Steven Ventimiglia
27,371 Points

I forgot that our Workspaces are actually limited to the accounts they were created with, however...

  1. Open the Workspace that you would like to download and share.
  2. Click "File" then click "Download Workspace".
  3. Save it as a .zip file.
  4. Upload it to Google Drive or Dropbox and provide a public link that we can download the .zip file from.