Created
May 20, 2018 10:14
-
-
Save JawsomeJason/2dab3363d2077bbb33a26bd6c71bb64a to your computer and use it in GitHub Desktop.
Easy auto-spacing for HTML siblings
This file contains 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
/* | |
* Automatically applies spacing to all non-inline siblings | |
* Disable in an element with `--SPACING-ENABLED: 0;`. Will automatically re-activate in children. Good for Grid Layout gap control. | |
* Change direction with `--SPACING-HORIZONTAL: 1` | |
*/ | |
* { | |
margin: 0; | |
/* change this to 1 if you need to space it from it's previous sibling. */ | |
--SPACING-ENABLED: 0; | |
--SPACING: 1em; | |
/* change this to 0 to make an element spaced horizontally instead */ | |
margin-top: calc(var(--SPACING) * var(--SPACING-ENABLED) * (1 - var(--SPACING-HORIZONTAL))); | |
/* DO NOT CHANGE */ | |
--SPACING-HORIZONTAL: 0; | |
margin-left: calc(var(--SPACING) * var(--SPACING-ENABLED) * var(--SPACING-HORIZONTAL)); | |
} | |
/* All non-first sibling will be spaced apart */ | |
body * + * { --SPACING-ENABLED: 1; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment