└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Hiccup 2 | 3 | A super strict yet probably too lenient methodology for writing maintainable CSS. 4 | 5 | 6 | 7 | ### Intention 8 | 9 | To encourage minimal markup and help write concise and maintainable css. 10 | 11 | ### Why 12 | 13 | Why not use just another CSS naming convention like BEM or OOCSS. I found that they were either too dictating, too restrictive, or just made my class names rediculosly huge like `.some-class__child-class--class-modifier` really??? O.o who wants that? 14 | 15 | ### How 16 | 17 | So how does it work? Please bear in mind that this is a living document and that it is subject to change. 18 | 19 | There are six kinds of classes used with the hiccup methodology: 20 | 21 | * Components 22 | * Sub-components - `*` 23 | * Children - `_` & `~` 24 | * Modifiers - `&` 25 | * States - `+` 26 | * Globals - `!` 27 | 28 | **Note**: we explicitly avoid using the `-` to identify classes so it can be used in class names (for example `.side-menu`) without gettign confusing. 29 | 30 | We differentiate these class types using prefixes as follows: 31 | 32 | **Globals**: 33 | 34 | ```scss 35 | .\!font-large { 36 | font-size: 30px; 37 | } 38 | ``` 39 | 40 | Globals are the only selector not typecast and that do not require the direct descendant selector as they can be used globally. 41 | 42 | **Components**: 43 | 44 | ```scss 45 | div.menu { 46 | background-color: lime; 47 | display: inline-block; 48 | min-width: 350px; 49 | height: 100vh; 50 | float: left; 51 | } 52 | ``` 53 | 54 | All classes **excluding globals** should be typecast to a certain element like `div.menu` why is this? 55 | When we write CSS we assume certain properties about the element we are going to apply the class to (for example that a `div` is `display: block;`). This means despite how CSS is usually written there is an intended HTML structure for said CSS. 56 | To strictly enforce the intended structure we require all classes be element typecast to force the correct semantics. 57 | 58 | As an added bonus this also speeds up the browsers CSS selector engine. 59 | 60 | **Children**: 61 | 62 | ```scss 63 | div.menu { 64 | //... 65 | a._menu\~link { 66 | display: block; 67 | padding: 10px; 68 | color: white; 69 | background-color: deepskyblue; 70 | border-bottom: 2px dashed white; 71 | text-decoration: none; 72 | } 73 | } 74 | ``` 75 | 76 | Like BEM we identify children using the `_` however we do this slightly differently using the `_` at the start of the class name followed by the parent component name with the `~` appended and then the class name of the child. This is so you can quickly differentiate between a new component and a components child. 77 | 78 | **Sub-components** 79 | 80 | ```scss 81 | div.\*profile { 82 | //... 83 | div._\*profile\~image { 84 | //... 85 | img { 86 | //... 87 | } 88 | } 89 | } 90 | ``` 91 | 92 | Sub-components are similar to components but with **two** big differences. 93 | 94 | **One**: sub-components explicity require that no components or sub-components be nested within them, this means you do not need to accomodate for any unknown markup within your component. 95 | 96 | _When is this prudent?_ 97 | 98 | Usually for elements where you may be utilizing `position: absolute;` (or other more explicit CSS properties) and you know exactly the elements you intended to have in the component and you only want to accomodated for them and no extra. 99 | 100 | **Two**: sub-components allow their children to target elements without classes for example: 101 | 102 | ```scss 103 | div.\*profile { 104 | //... 105 | div._\*profile\~image { 106 | //... 107 | img { 108 | //... 109 | } 110 | span { 111 | //... 112 | } 113 | } 114 | } 115 | ``` 116 | 117 | _Why bother?_ 118 | 119 | When I set out to create hiccup one of my biggest frustrations with BEM was for things like a sub-component where I knew nothing would ever be nested within the component but I still had to adhere to giving every element I styled a class name including **wrapping elements** which make for (IMHO) terrible markup. Who wants to read: 120 | 121 | ```html 122 |