Last active
August 29, 2015 14:13
-
-
Save yratof/ec728ad297afcb58c341 to your computer and use it in GitHub Desktop.
Sass Gallery that changes the layout based upon how many images there are
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Gallery example | |
--------------- | |
This will list successive images | |
in different ways, based on how | |
many images there are together. | |
*/ | |
.gallery { | |
max-width: 1200px; | |
width: 96%; | |
margin: 0 auto; | |
img { | |
float: left; | |
margin-bottom: 1%; | |
&:only-child { | |
max-width: 100%; | |
} | |
// | |
&:first-child { | |
// Two Images | |
&:nth-last-child(2) { | |
~ img { | |
margin-right: 1%; | |
max-width: 49.5%; | |
} | |
margin-right: 1%; | |
max-width: 49.5%; | |
} | |
// Three Images | |
&:nth-last-child(3) { | |
~ img { | |
margin-right: 1%; | |
max-width: 32.6%; | |
} | |
margin-right: 1%; | |
max-width: 32.6%; | |
} | |
// Four Images | |
&:nth-last-child(4) { | |
~ img { | |
margin-right: 1%; | |
max-width: 24.25%; | |
} | |
margin-right: 1%; | |
max-width: 24.25%; | |
} | |
} | |
&:nth-last-of-type(1) { | |
margin-right: 0 !important; | |
} | |
&:first-child { | |
// Five Images | |
&:nth-last-child(3n+5) { | |
~ img { | |
margin-right: 1%; | |
max-width: 49.5%; | |
} | |
margin-right: 1%; | |
max-width: 49.5%; | |
+ img ~ img { | |
margin-right: 1%; | |
max-width: 32.6%; | |
} | |
~ img:nth-child(3n+2) { | |
margin-right: 0; | |
} | |
} | |
// Six Images | |
&:nth-last-child(3n+6) { | |
~ img { | |
margin-right: 1%; | |
max-width: 32.6%; | |
&:nth-child(3n) { | |
margin-right: 0; | |
} | |
} | |
margin-right: 1%; | |
max-width: 32.6%; | |
} | |
// Seven Images | |
&:nth-last-child(3n+7) { | |
~ img { | |
margin-right: 1%; | |
max-width: 49.5%; | |
} | |
margin-right: 1%; | |
max-width: 49.5%; | |
+ img { | |
+ img + img ~ img { | |
margin-right: 1%; | |
max-width: 32.6%; | |
} | |
margin-right: 0; | |
} | |
~ img:nth-child(3n+4) { | |
margin-right: 0; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment