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

Stephen Blank
Stephen Blank
16,286 Points

Sass refactoring

Is there any way to refactor the following code into something DRY?

#instafeed a:nth-of-type(1) {
    visibility: hidden;
}

#instafeed a:nth-of-type(13) {
    visibility: hidden;
}

#instafeed a:nth-of-type(25) {
    visibility: hidden;
}

#instafeed a:nth-of-type(37) {
    visibility: hidden;
}

#instafeed a:nth-of-type(49) {
    visibility: hidden;
}


#instafeed a:nth-of-type(1n):nth-of-type(-n+6) {
    right: 8.8%;
}

#instafeed a:nth-of-type(1n+13):nth-of-type(-n+18) {
    right: 8.8%;
}

#instafeed a:nth-of-type(1n+25):nth-of-type(-n+30) {
    right: 8.8%;
}

#instafeed a:nth-of-type(1n+37):nth-of-type(-n+42) {
    right: 8.8%;
}

#instafeed a:nth-of-type(1n+49):nth-of-type(-n+54) {
    right: 8.8%;
}

Hi Steve,

I'm not sure if you're asking for simpler sass that will produce that exact css or if that css can be simplified and then sass on top of that to simplify further.

Also, do you need to stop at 49 and 54 or was that as high as you went because that's the number of items you currently have to deal with?

The solution will change depending on whether the pattern stops or needs to continue on for an unknown number of items.

1 Answer