Created
July 13, 2018 21:58
-
-
Save Bizarrus/56b48e070f4db2fc48d1b53e0085d158 to your computer and use it in GitHub Desktop.
Create easy CSS-based alphabetical order with SASS and FlexBox
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
// Specific the element (for sample "div" or "li") | |
$element: null !default; | |
// Define the Attribute (for sample <div data-ao="YourName">), "ao" is "alphabetical order" | |
$attribute: data-ao !default; | |
// Define the characters (with lower- and uppercase) | |
$characters: ( | |
(a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G), (h, H), (i, I), (j, J), (k, K), (l, L), (m, M), (n, N), (o, O), (p, P), (q, Q), (r, R), (s, S), (t, T), (u, U), (v, V), (w, W), (x, X), (y, Y), (z, Z) | |
); | |
@each $lower, $upper in $characters { | |
// calculate the order dynamically... | |
$index: index(($characters), ($lower, $upper)); | |
$folder: $index + 100; | |
$dot: $index + 1000; | |
$file: $index + 100000; | |
// Build the code... | |
#{$element}[#{$attribute}^="F.#{$lower}"], #{$element}[#{$attribute}^="F.#{$upper}"] { | |
order: $file + $dot; | |
} | |
#{$element}[#{$attribute}^="D.#{$lower}"], #{$element}[#{$attribute}^="D.#{$upper}"] { | |
order: $folder + $dot; | |
} | |
#{$element}[#{$attribute}^="F#{$lower}"], #{$element}[#{$attribute}^="F#{$upper}"] { | |
order: $file; | |
} | |
#{$element}[#{$attribute}^="D#{$lower}"], #{$element}[#{$attribute}^="D#{$upper}"] { | |
order: $folder; | |
} | |
#{$element}[#{$attribute}^=".#{$lower}"], #{$element}[#{$attribute}^=".#{$upper}"] { | |
order: $dot; | |
} | |
#{$element}[#{$attribute}^="#{$lower}"], #{$element}[#{$attribute}^="#{$upper}"] { | |
order: $dot; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment