Update format

This commit is contained in:
Angelos Chalaris
2020-04-30 13:21:04 +03:00
parent d9fd2d23c3
commit 2fbd3e0737
55 changed files with 412 additions and 571 deletions

74
package-lock.json generated
View File

@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@30-seconds/integration-tools": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@30-seconds/integration-tools/-/integration-tools-2.1.0.tgz",
"integrity": "sha512-lqVYh6qjetvtUTviciVlls+aJCSForj3THn+A/9nxYXwEQFKqlboqYs1k8qwMh9eHH2CDfRdLYGruo9E0WPXmg==",
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@30-seconds/integration-tools/-/integration-tools-2.2.0.tgz",
"integrity": "sha512-1EY0zkCU3N4TPyjqmqJNLmSquLQB+26qE4KLu01D9sSP67CaURJT3w/6IriHafv4GydrsVTNMLYPwFgLf9mA+g==",
"dev": true,
"requires": {
"@babel/core": "^7.7.4",
@ -28,19 +28,19 @@
}
},
"@babel/core": {
"version": "7.9.0",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.9.0.tgz",
"integrity": "sha512-kWc7L0fw1xwvI0zi8OKVBuxRVefwGOrKSQMvrQ3dW+bIIavBY3/NpXmpjMy7bQnLgwgzWQZ8TlM57YHpHNHz4w==",
"version": "7.9.6",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.9.6.tgz",
"integrity": "sha512-nD3deLvbsApbHAHttzIssYqgb883yU/d9roe4RZymBCDaZryMJDbptVpEpeQuRh4BJ+SYI8le9YGxKvFEvl1Wg==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.8.3",
"@babel/generator": "^7.9.0",
"@babel/generator": "^7.9.6",
"@babel/helper-module-transforms": "^7.9.0",
"@babel/helpers": "^7.9.0",
"@babel/parser": "^7.9.0",
"@babel/helpers": "^7.9.6",
"@babel/parser": "^7.9.6",
"@babel/template": "^7.8.6",
"@babel/traverse": "^7.9.0",
"@babel/types": "^7.9.0",
"@babel/traverse": "^7.9.6",
"@babel/types": "^7.9.6",
"convert-source-map": "^1.7.0",
"debug": "^4.1.0",
"gensync": "^1.0.0-beta.1",
@ -52,12 +52,12 @@
}
},
"@babel/generator": {
"version": "7.9.5",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.9.5.tgz",
"integrity": "sha512-GbNIxVB3ZJe3tLeDm1HSn2AhuD/mVcyLDpgtLXa5tplmWrJdF/elxB56XNqCuD6szyNkDi6wuoKXln3QeBmCHQ==",
"version": "7.9.6",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.9.6.tgz",
"integrity": "sha512-+htwWKJbH2bL72HRluF8zumBxzuX0ZZUFl3JLNyoUjM/Ho8wnVpPXM6aUz8cfKDqQ/h7zHqKt4xzJteUosckqQ==",
"dev": true,
"requires": {
"@babel/types": "^7.9.5",
"@babel/types": "^7.9.6",
"jsesc": "^2.5.1",
"lodash": "^4.17.13",
"source-map": "^0.5.0"
@ -126,15 +126,15 @@
}
},
"@babel/helper-replace-supers": {
"version": "7.8.6",
"resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.8.6.tgz",
"integrity": "sha512-PeMArdA4Sv/Wf4zXwBKPqVj7n9UF/xg6slNRtZW84FM7JpE1CbG8B612FyM4cxrf4fMAMGO0kR7voy1ForHHFA==",
"version": "7.9.6",
"resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.9.6.tgz",
"integrity": "sha512-qX+chbxkbArLyCImk3bWV+jB5gTNU/rsze+JlcF6Nf8tVTigPJSI1o1oBow/9Resa1yehUO9lIipsmu9oG4RzA==",
"dev": true,
"requires": {
"@babel/helper-member-expression-to-functions": "^7.8.3",
"@babel/helper-optimise-call-expression": "^7.8.3",
"@babel/traverse": "^7.8.6",
"@babel/types": "^7.8.6"
"@babel/traverse": "^7.9.6",
"@babel/types": "^7.9.6"
}
},
"@babel/helper-simple-access": {
@ -163,14 +163,14 @@
"dev": true
},
"@babel/helpers": {
"version": "7.9.2",
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.9.2.tgz",
"integrity": "sha512-JwLvzlXVPjO8eU9c/wF9/zOIN7X6h8DYf7mG4CiFRZRvZNKEF5dQ3H3V+ASkHoIB3mWhatgl5ONhyqHRI6MppA==",
"version": "7.9.6",
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.9.6.tgz",
"integrity": "sha512-tI4bUbldloLcHWoRUMAj4g1bF313M/o6fBKhIsb3QnGVPwRm9JsNf/gqMkQ7zjqReABiffPV6RWj7hEglID5Iw==",
"dev": true,
"requires": {
"@babel/template": "^7.8.3",
"@babel/traverse": "^7.9.0",
"@babel/types": "^7.9.0"
"@babel/traverse": "^7.9.6",
"@babel/types": "^7.9.6"
}
},
"@babel/highlight": {
@ -185,9 +185,9 @@
}
},
"@babel/parser": {
"version": "7.9.4",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.9.4.tgz",
"integrity": "sha512-bC49otXX6N0/VYhgOMh4gnP26E9xnDZK3TmbNpxYzzz9BQLBosQwfyOe9/cXUU3txYhTzLCbcqd5c8y/OmCjHA==",
"version": "7.9.6",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.9.6.tgz",
"integrity": "sha512-AoeIEJn8vt+d/6+PXDRPaksYhnlbMIiejioBZvvMQsOjW/JYK6k/0dKnvvP3EhK5GfMBWDPtrxRtegWdAcdq9Q==",
"dev": true
},
"@babel/template": {
@ -202,26 +202,26 @@
}
},
"@babel/traverse": {
"version": "7.9.5",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.9.5.tgz",
"integrity": "sha512-c4gH3jsvSuGUezlP6rzSJ6jf8fYjLj3hsMZRx/nX0h+fmHN0w+ekubRrHPqnMec0meycA2nwCsJ7dC8IPem2FQ==",
"version": "7.9.6",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.9.6.tgz",
"integrity": "sha512-b3rAHSjbxy6VEAvlxM8OV/0X4XrG72zoxme6q1MOoe2vd0bEc+TwayhuC1+Dfgqh1QEG+pj7atQqvUprHIccsg==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.8.3",
"@babel/generator": "^7.9.5",
"@babel/generator": "^7.9.6",
"@babel/helper-function-name": "^7.9.5",
"@babel/helper-split-export-declaration": "^7.8.3",
"@babel/parser": "^7.9.0",
"@babel/types": "^7.9.5",
"@babel/parser": "^7.9.6",
"@babel/types": "^7.9.6",
"debug": "^4.1.0",
"globals": "^11.1.0",
"lodash": "^4.17.13"
}
},
"@babel/types": {
"version": "7.9.5",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.9.5.tgz",
"integrity": "sha512-XjnvNqenk818r5zMaba+sLQjnbda31UfUURv3ei0qPQw4u+j2jMyJ5b11y8ZHYTRSI3NnInQkkkRT4fLqqPdHg==",
"version": "7.9.6",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.9.6.tgz",
"integrity": "sha512-qxXzvBO//jO9ZnoasKF1uJzHd2+M6Q2ZPIVfnFps8JJvXy0ZBbwbNOmE6SGIY5XOY6d1Bo5lb9d9RJ8nv3WSeA==",
"dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.9.5",

View File

@ -9,6 +9,6 @@
"author": "atomiks",
"license": "MIT",
"devDependencies": {
"@30-seconds/integration-tools": "^2.1.0"
"@30-seconds/integration-tools": "^2.2.0"
}
}

View File

@ -5,6 +5,10 @@ tags: other,intermediate
Explain briefly what the snippet does.
- Explain briefly how the snippet works.
- Use bullet points for your snippet's explanation.
- Try to explain everything briefly but clearly.
```html
<div class="my-snippet"></div>
```
@ -22,9 +26,3 @@ console.log(
"This is optional, if your snippet doesn't require JavaScript, be sure to delete this block!"
)
```
#### Explanation
- Explain briefly how the snippet works.
- Use bullet points for your snippet's explanation.
- Try to explain everything briefly but clearly.

View File

@ -6,8 +6,7 @@
"type": "snippet",
"attributes": {
"fileName": "border-with-top-triangle.md",
"text": "Creates a text container with a triangle at the top.\n\n",
"explanation": "\n\n- Use the `:before` and `:after` pseudo-elements to create two triangles.\n- The color of the `:before` triangle should be the same as the container's border color.\n- The color of the `:after` triangle should be the same as the container's background color.\n- The border width of the `:before` triangle should be `1px` wider than the `:after` triangle, in order to act as the border.\n- The `:after` triangle should be `1px` to the right of the `:before` triangle to allow for its left border to be shown.\n",
"text": "Creates a text container with a triangle at the top.\n\n- Use the `:before` and `:after` pseudo-elements to create two triangles.\n- The color of the `:before` triangle should be the same as the container's border color.\n- The color of the `:after` triangle should be the same as the container's background color.\n- The border width of the `:before` triangle should be `1px` wider than the `:after` triangle, in order to act as the border.\n- The `:after` triangle should be `1px` to the right of the `:before` triangle to allow for its left border to be shown.\n\n",
"codeBlocks": {
"html": "<div class=\"container\">\n Border with top triangle\n</div>",
"css": ".container {\n position: relative;\n background: #ffffff;\n padding: 15px;\n border: 1px solid #dddddd;\n margin-top: 20px;\n}\n\n.container:before, .container:after {\n content: '';\n position: absolute;\n bottom: 100%;\n left: 19px;\n border: 11px solid transparent;\n border-bottom-color: #dddddd;\n}\n\n.container:after {\n left: 20px;\n border: 10px solid transparent;\n border-bottom-color: #ffffff;\n}",
@ -20,7 +19,7 @@
]
},
"meta": {
"hash": "f8e3d8bea3ba89295f505ac71844ba18da485fc949e36433916a5570b75511d1",
"hash": "bfce79584ee85faf870c738918b8c65151c91e1cf03c34ad0535a3eec6341b07",
"firstSeen": "1547806723",
"lastUpdated": "1588157277",
"updateCount": 7,
@ -33,8 +32,7 @@
"type": "snippet",
"attributes": {
"fileName": "bouncing-loader.md",
"text": "Creates a bouncing loader animation.\n\n",
"explanation": "\n\nNote: `1rem` is usually `16px`.\n\n- `@keyframes` defines an animation that has two states, where the element changes `opacity` and is translated up on the 2D plane using `transform: translate3d()`. Using a single axis translation on `transform: translate3d()` improves the performance of the animation.\n- `.bouncing-loader` is the parent container of the bouncing circles and uses `display: flex` and `justify-content: center` to position them in the center.\n- `.bouncing-loader > div`, targets the three child `div`s of the parent to be styled. The `div`s are given a width and height of `1rem`, using `border-radius: 50%` to turn them from squares to circles.\n- `margin: 3rem 0.2rem` specifies that each circle has a top/bottom margin of `3rem` and left/right margin of `0.2rem` so that they do not directly touch each other, giving them some breathing room.\n- `animation` is a shorthand property for the various animation properties: `animation-name`, `animation-duration`, `animation-iteration-count`, `animation-direction` are used.\n- `nth-child(n)` targets the element which is the nth child of its parent.\n- `animation-delay` is used on the second and third `div` respectively, so that each element does not start the animation at the same time.\n",
"text": "Creates a bouncing loader animation.\n\n- `@keyframes` defines an animation that has two states, where the element changes `opacity` and is translated up on the 2D plane using `transform: translate3d()`. Using a single axis translation on `transform: translate3d()` improves the performance of the animation.\n- `.bouncing-loader` is the parent container of the bouncing circles and uses `display: flex` and `justify-content: center` to position them in the center.\n- `.bouncing-loader > div`, targets the three child `div`s of the parent to be styled. The `div`s are given a width and height of `1rem`, using `border-radius: 50%` to turn them from squares to circles.\n- `margin: 3rem 0.2rem` specifies that each circle has a top/bottom margin of `3rem` and left/right margin of `0.2rem` so that they do not directly touch each other, giving them some breathing room.\n- `animation` is a shorthand property for the various animation properties: `animation-name`, `animation-duration`, `animation-iteration-count`, `animation-direction` are used.\n- `nth-child(n)` targets the element which is the nth child of its parent.\n- `animation-delay` is used on the second and third `div` respectively, so that each element does not start the animation at the same time.\n- Note that `1rem` is usually `16px`.\n\n",
"codeBlocks": {
"html": "<div class=\"bouncing-loader\">\n <div></div>\n <div></div>\n <div></div>\n</div>",
"css": "@keyframes bouncing-loader {\n to {\n opacity: 0.1;\n transform: translate3d(0, -1rem, 0);\n }\n}\n\n.bouncing-loader {\n display: flex;\n justify-content: center;\n}\n\n.bouncing-loader > div {\n width: 1rem;\n height: 1rem;\n margin: 3rem 0.2rem;\n background: #8385aa;\n border-radius: 50%;\n animation: bouncing-loader 0.6s infinite alternate;\n}\n\n.bouncing-loader > div:nth-child(2) {\n animation-delay: 0.2s;\n}\n\n.bouncing-loader > div:nth-child(3) {\n animation-delay: 0.4s;\n}",
@ -47,7 +45,7 @@
]
},
"meta": {
"hash": "ad868220eb97c1c2704ead1d8669d22b1193ad3bed404e698930343b55e2fc2b",
"hash": "bc5cd3ddbcea729413f3dd786c268d459075eb8db5e1eea9fd1be3909e8277e2",
"firstSeen": "1520137462",
"lastUpdated": "1588157277",
"updateCount": 16,
@ -60,8 +58,7 @@
"type": "snippet",
"attributes": {
"fileName": "box-sizing-reset.md",
"text": "Resets the box-model so that `width` and `height` are not affected by `border` or `padding`.\n\n",
"explanation": "\n\n- `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.\n- `box-sizing: inherit` makes an element respect its parent's `box-sizing` rule.\n",
"text": "Resets the box-model so that `width` and `height` are not affected by `border` or `padding`.\n\n- `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.\n- `box-sizing: inherit` makes an element respect its parent's `box-sizing` rule.\n\n",
"codeBlocks": {
"html": "<div class=\"box\">border-box</div>\n<div class=\"box content-box\">content-box</div>",
"css": "div {\n box-sizing: border-box;\n}\n\n*,\n*:before,\n*:after {\n box-sizing: inherit;\n}\n\n.box {\n display: inline-block;\n width: 120px;\n height: 120px;\n padding: 8px;\n background: #F24333;\n color: white;\n border: 1px solid #BA1B1D;\n border-radius: 4px;\n}\n\n.content-box {\n box-sizing: content-box;\n}",
@ -74,7 +71,7 @@
]
},
"meta": {
"hash": "6c0ddb17ff1fd43696cdb682cb7f99584ece58261a7acb4026a8721c0f7a77f8",
"hash": "89fd45ba7a9ec6ddeeec12ce27b799fa1592a6a87339ba3828b69b914f73ea69",
"firstSeen": "1519750749",
"lastUpdated": "1588157277",
"updateCount": 17,
@ -87,8 +84,7 @@
"type": "snippet",
"attributes": {
"fileName": "button-border-animation.md",
"text": "Creates a border animation on hover.\n\n",
"explanation": "\n\n- Use the `:before` and `:after` pseudo-elements as borders that animate on hover.\n",
"text": "Creates a border animation on hover.\n\n- Use the `:before` and `:after` pseudo-elements as borders that animate on hover.\n\n",
"codeBlocks": {
"html": "<button class=\"animated-border-button\">Submit</button>",
"css": ".animated-border-button {\n background-color: #141414;\n border: none;\n color: #ffffff;\n outline: none;\n padding: 12px 40px 10px;\n position: relative;\n}\n\n.animated-border-button:before,\n.animated-border-button:after {\n border: 0 solid transparent;\n transition: all 0.3s;\n content: '';\n height: 0;\n position: absolute;\n width: 24px;\n}\n\n.animated-border-button:before {\n border-top: 2px solid #141414;\n right: 0;\n top: -4px;\n}\n\n.animated-border-button:after {\n border-bottom: 2px solid #141414;\n bottom: -4px;\n left: 0;\n}\n\n.animated-border-button:hover:before,\n.animated-border-button:hover:after {\n width: 100%;\n}",
@ -101,7 +97,7 @@
]
},
"meta": {
"hash": "b96987e7b89fdaf77ad52a8f2ef31b0024af9e84060a3dc636840b2bf567416e",
"hash": "7ca6d2119b1378e0c5a6eb8cca3b693e5495f427535f61764bfb7d26d94f5021",
"firstSeen": "1548089566",
"lastUpdated": "1588157277",
"updateCount": 10,
@ -114,8 +110,7 @@
"type": "snippet",
"attributes": {
"fileName": "circle.md",
"text": "Creates a circle shape with pure CSS.\n\n",
"explanation": "\n\n- `border-radius: 50%` curves the borders of an element to create a circle.\n- Since a circle has the same radius at any given point, the `width` and `height` must be the same. Differing values will create an ellipse.\n",
"text": "Creates a circle shape with pure CSS.\n\n- `border-radius: 50%` curves the borders of an element to create a circle.\n- Since a circle has the same radius at any given point, the `width` and `height` must be the same. Differing values will create an ellipse.\n\n",
"codeBlocks": {
"html": "<div class=\"circle\"></div>",
"css": ".circle {\n border-radius: 50%;\n width: 2rem;\n height: 2rem;\n background: #333;\n}",
@ -128,7 +123,7 @@
]
},
"meta": {
"hash": "aafd001218b814a598cee1132c44bbfa5d43baf6d6b162d9815f6222753d0b38",
"hash": "c4a5d5f38ddc713a715c1ecd090eeb566b27ab523ad7341905dd6768c905d20d",
"firstSeen": "1520144392",
"lastUpdated": "1588157277",
"updateCount": 13,
@ -141,8 +136,7 @@
"type": "snippet",
"attributes": {
"fileName": "clearfix.md",
"text": "Ensures that an element self-clears its children.\n\n",
"explanation": "\n\n- `.clearfix:after` defines a pseudo-element.\n- `content: ''` allows the pseudo-element to affect layout.\n- `clear: both` indicates that the left, right or both sides of the element cannot be adjacent to earlier floated elements within the same block formatting context.\n- This is only useful if you are still using `float` to build layouts. Please consider using a modern approach with flexbox layout or grid layout. For this snippet to work properly you need to ensure that there are no non-floating children in the container and that there are no tall floats before the clearfixed container but in the same formatting context (e.g. floated columns).\n",
"text": "Ensures that an element self-clears its children.\n\n- `.clearfix:after` defines a pseudo-element.\n- `content: ''` allows the pseudo-element to affect layout.\n- `clear: both` indicates that the left, right or both sides of the element cannot be adjacent to earlier floated elements within the same block formatting context.\n- This is only useful if you are still using `float` to build layouts. Please consider using a modern approach with flexbox layout or grid layout. For this snippet to work properly you need to ensure that there are no non-floating children in the container and that there are no tall floats before the clearfixed container but in the same formatting context (e.g. floated columns).\n\n",
"codeBlocks": {
"html": "<div class=\"clearfix\">\n <div class=\"floated\">float a</div>\n <div class=\"floated\">float b</div>\n <div class=\"floated\">float c</div>\n</div>",
"css": ".clearfix:after {\n content: '';\n display: block;\n clear: both;\n}\n\n.floated {\n float: left;\n}",
@ -155,7 +149,7 @@
]
},
"meta": {
"hash": "0f47f41b48ebe7519596fa605738f40a04282591e5496fb775fd218e1afa1ea9",
"hash": "0ad1a0912a2aec670ef55640171565812a756c5ea0981d69b7a1d16e82f2a8cc",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 17,
@ -168,8 +162,7 @@
"type": "snippet",
"attributes": {
"fileName": "constant-width-to-height-ratio.md",
"text": "Given an element of variable width, it will ensure its `height` remains proportionate in a responsive fashion (i.e. its `width` to `height` ratio remains constant).\n\n",
"explanation": "\n\n- `padding-top` on the `:before` pseudo-element causes the height of the element to equal a percentage of its width. `100%` therefore means the element's height will always be `100%` of the width, creating a responsive square.\n- This method also allows content to be placed inside the element normally.\n",
"text": "Given an element of variable width, it will ensure its `height` remains proportionate in a responsive fashion (i.e. its `width` to `height` ratio remains constant).\n\n- `padding-top` on the `:before` pseudo-element causes the height of the element to equal a percentage of its width. `100%` therefore means the element's height will always be `100%` of the width, creating a responsive square.\n- This method also allows content to be placed inside the element normally.\n\n",
"codeBlocks": {
"html": "<div class=\"constant-width-to-height-ratio\"></div>",
"css": ".constant-width-to-height-ratio {\n background: #333;\n width: 50%;\n}\n\n.constant-width-to-height-ratio:before {\n content: '';\n padding-top: 100%;\n float: left;\n}\n\n.constant-width-to-height-ratio:after {\n content: '';\n display: block;\n clear: both;\n}",
@ -182,7 +175,7 @@
]
},
"meta": {
"hash": "a52235ca71e0e33bb9b38b4bfdb35d3af10ff5a8bcaf9801c33b70a5b30d9f25",
"hash": "cf8a79518956dec343121a89a0aafcca46e421ae755cad72aa508e557d7bf355",
"firstSeen": "1519721126",
"lastUpdated": "1588157277",
"updateCount": 16,
@ -195,8 +188,7 @@
"type": "snippet",
"attributes": {
"fileName": "counter.md",
"text": "Counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used.\n\n",
"explanation": "\n\nYou can create a ordered list using any type of HTML.\n\n- `counter-reset` is used to initialize a counter, the name of which is the value of the attribute. By default, the counter starts at `0`. This property can also be used to change its value to any specific number.\n- `counter-increment` is used for an element that will be countable. Once `counter-reset` is initialized, a counter's value can be increased or decreased.\n- `counter(name, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive two parameters, the first being the name of the counter and the second one either `decimal` or `upper-roman` (`decimal` by default).\n- `counters(counter, string, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be `decimal` or `upper-roman` (`decimal` by default).\n- A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the `counters()` function, separating text can be inserted between different levels of nested counters.\n",
"text": "Counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used.\n\n- `counter-reset` is used to initialize a counter, the name of which is the value of the attribute. By default, the counter starts at `0`. This property can also be used to change its value to any specific number.\n- `counter-increment` is used for an element that will be countable. Once `counter-reset` is initialized, a counter's value can be increased or decreased.\n- `counter(name, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive two parameters, the first being the name of the counter and the second one either `decimal` or `upper-roman` (`decimal` by default).\n- `counters(counter, string, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be `decimal` or `upper-roman` (`decimal` by default).\n- A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the `counters()` function, separating text can be inserted between different levels of nested counters.\n- Note that you can create an ordered list using any type of HTML.\n\n",
"codeBlocks": {
"html": "<ul>\n <li>List item</li>\n <li>List item</li>\n <li>\n List item\n <ul>\n <li>List item</li>\n <li>List item</li>\n <li>List item</li>\n </ul>\n </li>\n</ul>",
"css": "ul {\n counter-reset: counter;\n}\n\nli:before {\n counter-increment: counter;\n content: counters(counter, '.') ' ';\n}",
@ -209,7 +201,7 @@
]
},
"meta": {
"hash": "27a5f632aa6e65b6260a6c0c55ea112f04a8ffb5398c2e1bee37626dad0aeecd",
"hash": "7453b5a9ca8d522a584bb23520dd042eb9af554029da89ae19b2a4ca3356691a",
"firstSeen": "1520453562",
"lastUpdated": "1588157277",
"updateCount": 20,
@ -222,8 +214,7 @@
"type": "snippet",
"attributes": {
"fileName": "custom-scrollbar.md",
"text": "Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.\n\n",
"explanation": "\n\n- `::-webkit-scrollbar` targets the whole scrollbar element.\n- `::-webkit-scrollbar-track` targets only the scrollbar track.\n- `::-webkit-scrollbar-thumb` targets the scrollbar thumb.\n- Apply the same selectors and styles without `.custom-scrollbar` to style the document scrollbar.\n- Scrollbar styling doesn't appear to be on any standards track. There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the [WebKit Blog](https://webkit.org/blog/363/styling-scrollbars/).\n",
"text": "Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.\n\n- `::-webkit-scrollbar` targets the whole scrollbar element.\n- `::-webkit-scrollbar-track` targets only the scrollbar track.\n- `::-webkit-scrollbar-thumb` targets the scrollbar thumb.\n- Apply the same selectors and styles without `.custom-scrollbar` to style the document scrollbar.\n- Scrollbar styling doesn't appear to be on any standards track. There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the [WebKit Blog](https://webkit.org/blog/363/styling-scrollbars/).\n\n",
"codeBlocks": {
"html": "<div class=\"custom-scrollbar\">\n <p>\n Lorem ipsum dolor sit amet consectetur adipisicing elit.<br />\n Iure id exercitationem nulla qui repellat laborum vitae, <br />\n molestias tempora velit natus. Quas, assumenda nisi. <br />\n Quisquam enim qui iure, consequatur velit sit?\n </p>\n</div>",
"css": ".custom-scrollbar {\n height: 70px;\n overflow-y: scroll;\n}\n\n.custom-scrollbar::-webkit-scrollbar {\n width: 8px;\n}\n\n.custom-scrollbar::-webkit-scrollbar-track {\n background: #1E3F20;\n border-radius: 12px;\n}\n\n.custom-scrollbar::-webkit-scrollbar-thumb {\n background: #4A7856;\n border-radius: 12px;\n}",
@ -236,7 +227,7 @@
]
},
"meta": {
"hash": "d05732925c15ead748f03c9f2f053aed0339c1a962d33d6a8a8a451f994bb46a",
"hash": "903dada31ae5189f2b1b9b67f1e9bb4ef0f8164b8458dd577c9aff1121e369b1",
"firstSeen": "1519893295",
"lastUpdated": "1588157277",
"updateCount": 15,
@ -249,8 +240,7 @@
"type": "snippet",
"attributes": {
"fileName": "custom-text-selection.md",
"text": "Changes the styling of text selection.\n\n",
"explanation": "\n\n- `::selection` defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.\n- Requires prefixes for full support and is not actually in any specification.\n",
"text": "Changes the styling of text selection.\n\n- `::selection` defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.\n- Requires prefixes for full support and is not actually in any specification.\n\n",
"codeBlocks": {
"html": "<p class=\"custom-text-selection\">Select some of this text.</p>",
"css": "::selection {\n background: aquamarine;\n color: black;\n}\n\n.custom-text-selection::selection {\n background: deeppink;\n color: white;\n}",
@ -263,7 +253,7 @@
]
},
"meta": {
"hash": "881222d40e158eba5312b94563a47ed3840a475ceab10a54265f8a0d263e9cd9",
"hash": "88dca6e56306f77c7f991b3f3a82da867c800c0aa2103246d22873a64c07f9c4",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 17,
@ -276,8 +266,7 @@
"type": "snippet",
"attributes": {
"fileName": "disable-selection.md",
"text": "Makes the content unselectable.\n\n",
"explanation": "\n\n- `user-select: none` specifies that the text cannot be selected.\n- This is not a secure method to prevent users from copying content.\n",
"text": "Makes the content unselectable.\n\n- `user-select: none` specifies that the text cannot be selected.\n- This is not a secure method to prevent users from copying content.\n\n",
"codeBlocks": {
"html": "<p>You can select me.</p>\n<p class=\"unselectable\">You can't select me!</p>",
"css": ".unselectable {\n user-select: none;\n}",
@ -290,7 +279,7 @@
]
},
"meta": {
"hash": "717294a4a01093025d81e6cb6a985d9a84849a439495fc0002c7f67e882f95b3",
"hash": "2c4bbeeb47f1fafb4759b9ea32a9f8f0d32d56307fa1b9606c2ce3035cdcef42",
"firstSeen": "1519664998",
"lastUpdated": "1588157277",
"updateCount": 16,
@ -303,8 +292,7 @@
"type": "snippet",
"attributes": {
"fileName": "display-table-centering.md",
"text": "Vertically and horizontally centers a child element within its parent element using `display: table` (as an alternative to `flexbox`).\n\n",
"explanation": "\n\n- `display: table` on '.center' allows the element to behave like a `<table>` HTML element.\n- 100% height and width on '.center' allows the element to fill the available space within its parent element.\n- `display: table-cell` on '.center > span' allows the element to behave like an <td> HTML element.\n- `text-align: center` on '.center > span' centers the child element horizontally.\n- `vertical-align: middle` on '.center > span' centers the child element vertically.\n- The outer parent ('.container' in this case) must have a fixed height and width.\n",
"text": "Vertically and horizontally centers a child element within its parent element using `display: table` (as an alternative to `flexbox`).\n\n- `display: table` on '.center' allows the element to behave like a `<table>` HTML element.\n- 100% height and width on '.center' allows the element to fill the available space within its parent element.\n- `display: table-cell` on '.center > span' allows the element to behave like an <td> HTML element.\n- `text-align: center` on '.center > span' centers the child element horizontally.\n- `vertical-align: middle` on '.center > span' centers the child element vertically.\n- The outer parent ('.container' in this case) must have a fixed height and width.\n\n",
"codeBlocks": {
"html": "<div class=\"container\">\n <div class=\"center\"><span>Centered content</span></div>\n</div>",
"css": ".container {\n border: 1px solid #333;\n height: 250px;\n width: 250px;\n}\n\n.center {\n display: table;\n height: 100%;\n width: 100%;\n}\n\n.center > span {\n display: table-cell;\n text-align: center;\n vertical-align: middle;\n}",
@ -317,7 +305,7 @@
]
},
"meta": {
"hash": "dc64222bbcae2e2fc731ae08628e140b962719f0734486bc407fd9569e0a1c0a",
"hash": "a63a3e21c2e6424b62010d45f51ac16f487e332b25cd55a0a4a13752608cca21",
"firstSeen": "1522361754",
"lastUpdated": "1588157277",
"updateCount": 16,
@ -330,8 +318,7 @@
"type": "snippet",
"attributes": {
"fileName": "donut-spinner.md",
"text": "Creates a donut spinner that can be used to indicate the loading of content.\n\n",
"explanation": "\n\n- Use a semi-transparent `border` for the whole element, except one side that will serve as the loading indicator for the donut. Use `animation` to rotate the element.\n",
"text": "Creates a donut spinner that can be used to indicate the loading of content.\n\n- Use a semi-transparent `border` for the whole element, except one side that will serve as the loading indicator for the donut. Use `animation` to rotate the element.\n\n",
"codeBlocks": {
"html": "<div class=\"donut\"></div>",
"css": "@keyframes donut-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n.donut {\n display: inline-block;\n border: 4px solid rgba(0, 0, 0, 0.1);\n border-left-color: #7983ff;\n border-radius: 50%;\n width: 30px;\n height: 30px;\n animation: donut-spin 1.2s linear infinite;\n}",
@ -344,7 +331,7 @@
]
},
"meta": {
"hash": "31dfcb657403ccf45f4f0f652cac95505f478a1e5c97ce9b9c3945c2cd6c0fc2",
"hash": "dffa4a03cbdffd14a3a6487d529d2fde3f148a8922c90456b74d5825288ef616",
"firstSeen": "1519745555",
"lastUpdated": "1588157277",
"updateCount": 15,
@ -357,8 +344,7 @@
"type": "snippet",
"attributes": {
"fileName": "drop-cap.md",
"text": "Makes the first letter in the first paragraph bigger than the rest of the text - often used to signify the beginning of a new section.\n\n",
"explanation": "\n\n- Use the `::first-letter` pseudo-element to style the first element of the paragraph, use the `:first-child` selector to select only the first paragraph.\n",
"text": "Makes the first letter in the first paragraph bigger than the rest of the text - often used to signify the beginning of a new section.\n\n- Use the `::first-letter` pseudo-element to style the first element of the paragraph, use the `:first-child` selector to select only the first paragraph.\n\n",
"codeBlocks": {
"html": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam commodo ligula quis tincidunt cursus. Integer consectetur tempor ex eget hendrerit. Cras facilisis sodales odio nec maximus. Pellentesque lacinia convallis libero, rhoncus tincidunt ante dictum at. Nullam facilisis lectus tellus, sit amet congue erat sodales commodo.</p>\n<p>Donec magna erat, imperdiet non odio sed, sodales tempus magna. Integer vitae orci lectus. Nullam consectetur orci at pellentesque efficitur.</p>",
"css": "p:first-child::first-letter {\n color: #5f79ff;\n float: left;\n margin: 0 8px 0 4px;\n font-size: 3rem;\n font-weight: bold;\n line-height: 1;\n}",
@ -371,7 +357,7 @@
]
},
"meta": {
"hash": "29fc5e79e9653ed4bc22e527ed552f9f657861f29acd1302961e0329f2f0052a",
"hash": "69acadb4dc478ac49a229a222c919092ec9f9a0bf7d30d65871a1332b347783b",
"firstSeen": "1539406050",
"lastUpdated": "1588157277",
"updateCount": 6,
@ -384,8 +370,7 @@
"type": "snippet",
"attributes": {
"fileName": "dynamic-shadow.md",
"text": "Creates a shadow similar to `box-shadow` but based on the colors of the element itself.\n\n",
"explanation": "\n\n- `position: relative` on the element establishes a Cartesian positioning context for psuedo-elements.\n- `z-index: 1` establishes a new stacking context.\n- `:after` defines a pseudo-element.\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 100%` and `height: 100%` sizes the pseudo-element to fill its parent's dimensions, making it equal in size.\n- `background: inherit` causes the pseudo-element to inherit the linear gradient specified on the element.\n- `top: 0.5rem` offsets the pseudo-element down slightly from its parent.\n- `filter: blur(0.4rem)` will blur the pseudo-element to create the appearance of a shadow underneath.\n- `opacity: 0.7` makes the pseudo-element partially transparent.\n- `z-index: -1` positions the pseudo-element behind the parent but in front of the background.\n",
"text": "Creates a shadow similar to `box-shadow` but based on the colors of the element itself.\n\n- `position: relative` on the element establishes a Cartesian positioning context for psuedo-elements.\n- `z-index: 1` establishes a new stacking context.\n- `:after` defines a pseudo-element.\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 100%` and `height: 100%` sizes the pseudo-element to fill its parent's dimensions, making it equal in size.\n- `background: inherit` causes the pseudo-element to inherit the linear gradient specified on the element.\n- `top: 0.5rem` offsets the pseudo-element down slightly from its parent.\n- `filter: blur(0.4rem)` will blur the pseudo-element to create the appearance of a shadow underneath.\n- `opacity: 0.7` makes the pseudo-element partially transparent.\n- `z-index: -1` positions the pseudo-element behind the parent but in front of the background.\n\n",
"codeBlocks": {
"html": "<div class=\"dynamic-shadow\"></div>",
"css": ".dynamic-shadow {\n position: relative;\n width: 10rem;\n height: 10rem;\n background: linear-gradient(75deg, #6d78ff, #00ffb8);\n z-index: 1;\n}\n\n.dynamic-shadow:after {\n content: '';\n width: 100%;\n height: 100%;\n position: absolute;\n background: inherit;\n top: 0.5rem;\n filter: blur(0.4rem);\n opacity: 0.7;\n z-index: -1;\n}",
@ -398,7 +383,7 @@
]
},
"meta": {
"hash": "8f4c102ff96ccb5d6db3007fa587e0e52fcac6950b4d2f55cc897f08627f7cc3",
"hash": "68bfbc2b81204c555c9a1160a9a6e459f56ecff2b8ef05a3cd163fa3db0864ee",
"firstSeen": "1520250696",
"lastUpdated": "1588157277",
"updateCount": 14,
@ -411,8 +396,7 @@
"type": "snippet",
"attributes": {
"fileName": "easing-variables.md",
"text": "Variables that can be reused for `transition-timing-function` properties, more powerful than the built-in `ease`, `ease-in`, `ease-out` and `ease-in-out`.\n\n",
"explanation": "\n\n- The variables are defined globally within the `:root` CSS pseudo-class which matches the root element of a tree representing the document.\n- In HTML, `:root` represents the `<html>` element and is identical to the selector `html`, except that its specificity is higher.\n",
"text": "Variables that can be reused for `transition-timing-function` properties, more powerful than the built-in `ease`, `ease-in`, `ease-out` and `ease-in-out`.\n\n- The variables are defined globally within the `:root` CSS pseudo-class which matches the root element of a tree representing the document.\n- In HTML, `:root` represents the `<html>` element and is identical to the selector `html`, except that its specificity is higher.\n\n",
"codeBlocks": {
"html": "<div class=\"easing-variables\">Hover</div>",
"css": ":root {\n /* Place variables in here to use globally */\n}\n\n.easing-variables {\n --ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);\n --ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);\n --ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);\n --ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);\n --ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);\n --ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);\n\n --ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);\n --ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);\n --ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);\n --ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);\n --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);\n --ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1);\n\n --ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);\n --ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1);\n --ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);\n --ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);\n --ease-in-out-expo: cubic-bezier(1, 0, 0, 1);\n --ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);\n display: inline-block;\n width: 75px;\n height: 75px;\n padding: 10px;\n color: white;\n line-height: 50px;\n text-align: center;\n background: #333;\n transition: transform 1s var(--ease-out-quart);\n}\n\n.easing-variables:hover {\n transform: rotate(45deg);\n}",
@ -425,7 +409,7 @@
]
},
"meta": {
"hash": "9f14ed77dd8967cb6ae259832f6dc4d95697220cefc8d0e2464af5d61f0adbbe",
"hash": "0cfe8785de5d1414d98d2f3b1392cab4c7ed98a5bed90d73189d8ffc339433c1",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 14,
@ -438,8 +422,7 @@
"type": "snippet",
"attributes": {
"fileName": "etched-text.md",
"text": "Creates an effect where text appears to be \"etched\" or engraved into the background.\n\n",
"explanation": "\n\n- `text-shadow: 0 2px white` creates a white shadow offset `0px` horizontally and `2px` vertically from the origin position.\n- The background must be darker than the shadow for the effect to work.\n- The text color should be slightly faded to make it look like it's engraved/carved out of the background.\n",
"text": "Creates an effect where text appears to be \"etched\" or engraved into the background.\n\n- `text-shadow: 0 2px white` creates a white shadow offset `0px` horizontally and `2px` vertically from the origin position.\n- The background must be darker than the shadow for the effect to work.\n- The text color should be slightly faded to make it look like it's engraved/carved out of the background.\n\n",
"codeBlocks": {
"html": "<p class=\"etched-text\">I appear etched into the background.</p>",
"css": ".etched-text {\n text-shadow: 0 2px white;\n font-size: 1.5rem;\n font-weight: bold;\n color: #b8bec5;\n}",
@ -452,7 +435,7 @@
]
},
"meta": {
"hash": "f94e652812b03848e5aff663bdafc1794c5bd3cae64c564041f8f98a9471d182",
"hash": "663895c6085e91e59e313905e3a5371d3d13313db629e8ae20585c45120537ba",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 14,
@ -465,8 +448,7 @@
"type": "snippet",
"attributes": {
"fileName": "evenly-distributed-children.md",
"text": "Evenly distributes child elements within a parent element.\n\n",
"explanation": "\n\n- `display: flex` enables flexbox.\n- `justify-content: space-between` evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.\n- Alternatively, use `justify-content: space-around` to distribute the children with space around them, rather than between them.\n\n",
"text": "Evenly distributes child elements within a parent element.\n\n- `display: flex` enables flexbox.\n- `justify-content: space-between` evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.\n- Alternatively, use `justify-content: space-around` to distribute the children with space around them, rather than between them.\n\n",
"codeBlocks": {
"html": "<div class=\"evenly-distributed-children\">\n <p>Item1</p>\n <p>Item2</p>\n <p>Item3</p>\n</div>",
"css": ".evenly-distributed-children {\n display: flex;\n justify-content: space-between;\n}",
@ -479,7 +461,7 @@
]
},
"meta": {
"hash": "dbaab5a8aba16d409371d56ee6923a2b59ed233e145f39419838de76073ccde0",
"hash": "e4767a09f4c0eaebe8a6a63174dfb3a093d4d6345263bdef617b1346cb28c7c5",
"firstSeen": "1519818422",
"lastUpdated": "1588157277",
"updateCount": 13,
@ -492,8 +474,7 @@
"type": "snippet",
"attributes": {
"fileName": "fit-image-in-container.md",
"text": "Changes the fit and position of an image within its container while preserving its aspect ratio. Previously only possible using a background image and the `background-size` property.\n\n",
"explanation": "\n\n- `object-fit: contain` fits the entire image within the container while preserving its aspect ratio.\n- `object-fit: cover` fills the container with the image while preserving its aspect ratio.\n- `object-position: [x] [y]` positions the image within the container.\n",
"text": "Changes the fit and position of an image within its container while preserving its aspect ratio. Previously only possible using a background image and the `background-size` property.\n\n- `object-fit: contain` fits the entire image within the container while preserving its aspect ratio.\n- `object-fit: cover` fills the container with the image while preserving its aspect ratio.\n- `object-position: [x] [y]` positions the image within the container.\n\n",
"codeBlocks": {
"html": "<img class=\"image image-contain\" src=\"https://picsum.photos/600/200\" />\n<img class=\"image image-cover\" src=\"https://picsum.photos/600/200\" />",
"css": ".image {\n background: #34495e;\n border: 1px solid #34495e;\n width: 200px;\n height: 200px;\n}\n\n.image-contain {\n object-fit: contain;\n object-position: center;\n}\n\n.image-cover {\n object-fit: cover;\n object-position: right top;\n}",
@ -507,7 +488,7 @@
]
},
"meta": {
"hash": "fff59c59a6e0291f465edd70e0c708317fd1a05a671ed8c424762607baffe888",
"hash": "2ee436f279eb47532f9911a38136887d9db687409fa4700ff66aa1a00f8f4143",
"firstSeen": "1540967689",
"lastUpdated": "1588157277",
"updateCount": 9,
@ -520,8 +501,7 @@
"type": "snippet",
"attributes": {
"fileName": "flexbox-centering.md",
"text": "Horizontally and vertically centers a child element within a parent element using `flexbox`.\n\n",
"explanation": "\n\n- `display: flex` creates a flexbox layout.\n- `justify-content: center` centers the child horizontally.\n- `align-items: center` centers the child vertically.\n",
"text": "Horizontally and vertically centers a child element within a parent element using `flexbox`.\n\n- `display: flex` creates a flexbox layout.\n- `justify-content: center` centers the child horizontally.\n- `align-items: center` centers the child vertically.\n\n",
"codeBlocks": {
"html": "<div class=\"flexbox-centering\">\n <div>Centered content.</div>\n</div>",
"css": ".flexbox-centering {\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100px;\n}",
@ -534,7 +514,7 @@
]
},
"meta": {
"hash": "53b37c008f374aed5bc8a606e882299adac01d2ae42933963919c92664221d90",
"hash": "ce48cad66b6e9359d311b35cb2d42d40a8d4cc98f9fecabb80714b24aefa966a",
"firstSeen": "1520071047",
"lastUpdated": "1588157277",
"updateCount": 13,
@ -547,8 +527,7 @@
"type": "snippet",
"attributes": {
"fileName": "focus-within.md",
"text": "Changes the appearance of a form if any of its children are focused.\n\n",
"explanation": "\n\n- The psuedo class `:focus-within` applies styles to a parent element if any child element gets focused. For example, an `input` element inside a `form` element.\n",
"text": "Changes the appearance of a form if any of its children are focused.\n\n- The psuedo class `:focus-within` applies styles to a parent element if any child element gets focused. For example, an `input` element inside a `form` element.\n\n",
"codeBlocks": {
"html": "<form>\n <label for=\"username\">Username:</label>\n <input id=\"username\" type=\"text\" />\n <br />\n <label for=\"password\">Password:</label>\n <input id=\"password\" type=\"text\" />\n</form>",
"css": "form {\n border: 2px solid #52B882;\n padding: 8px;\n border-radius: 2px;\n}\n\nform:focus-within {\n background: #7CF0BD;\n}\n\nlabel {\n display: inline-block;\n width: 72px;\n}\n\ninput {\n margin: 4px;\n}",
@ -562,7 +541,7 @@
]
},
"meta": {
"hash": "9979d294e5ccc7a4255961c0f0527f9687114973137a5ab3d2bef4828cc65ccf",
"hash": "b495903a17e91e0a4fdeb5db0181de46f858acaa08f4007d75c262e504673cdc",
"firstSeen": "1540256293",
"lastUpdated": "1588157277",
"updateCount": 14,
@ -575,8 +554,7 @@
"type": "snippet",
"attributes": {
"fileName": "fullscreen.md",
"text": "The `:fullscreen` CSS pseudo-element represents an element that's displayed when the browser is in fullscreen mode.\n\n",
"explanation": "\n\n- `:fullscreen` CSS pseudo-element selector is used to select and style an element that is being displayed in fullscreen mode.\n",
"text": "The `:fullscreen` CSS pseudo-element represents an element that's displayed when the browser is in fullscreen mode.\n\n- `:fullscreen` CSS pseudo-element selector is used to select and style an element that is being displayed in fullscreen mode.\n\n",
"codeBlocks": {
"html": "<div class=\"container\">\n <p><em>Click the button below to enter the element into fullscreen mode. </em></p>\n <div class=\"element\" id=\"element\"><p>I change color in fullscreen mode!</p></div>\n <br />\n <button onclick=\"var el = document.getElementById('element'); el.requestFullscreen();\">\n Go Full Screen!\n </button>\n</div>",
"css": ".container {\n margin: 40px auto;\n max-width: 700px;\n}\n\n.element {\n padding: 20px;\n height: 300px;\n width: 100%;\n background-color: skyblue;\n box-sizing: border-box;\n}\n\n.element p {\n text-align: center;\n color: white;\n font-size: 3em;\n}\n\n.element:-ms-fullscreen p {\n visibility: visible;\n}\n\n.element:fullscreen {\n background-color: #e4708a;\n width: 100vw;\n height: 100vh;\n}",
@ -589,7 +567,7 @@
]
},
"meta": {
"hash": "afd6ca97e87bb904559d0913178f8cdc6983785f1100ca71c84ce1747a050923",
"hash": "1ab78b7504ac5a130017f34c8893118bf0ada584b5d02bfd9ef83e176a524192",
"firstSeen": "1547291320",
"lastUpdated": "1588157277",
"updateCount": 11,
@ -602,8 +580,7 @@
"type": "snippet",
"attributes": {
"fileName": "gradient-text.md",
"text": "Gives text a gradient color.\n\n",
"explanation": "\n\n- `background: -webkit-linear-gradient(...)` gives the text element a gradient background.\n- `webkit-text-fill-color: transparent` fills the text with a transparent color.\n- `webkit-background-clip: text` clips the background with the text, filling the text with the gradient background as the color.\n- Uses non-standard properties.\n",
"text": "Gives text a gradient color.\n\n- `background: -webkit-linear-gradient(...)` gives the text element a gradient background.\n- `webkit-text-fill-color: transparent` fills the text with a transparent color.\n- `webkit-background-clip: text` clips the background with the text, filling the text with the gradient background as the color.\n- Uses non-standard properties.\n\n",
"codeBlocks": {
"html": "<p class=\"gradient-text\">Gradient text</p>",
"css": ".gradient-text {\n background: linear-gradient(#70D6FF, #00072D);\n -webkit-text-fill-color: transparent;\n -webkit-background-clip: text;\n font-size: 32px;\n}",
@ -616,7 +593,7 @@
]
},
"meta": {
"hash": "66f2df76ea9401a3ac447bf4529ba187f29898d924f4a13f835532c86ee65a6c",
"hash": "e2e7d5612386137a4aa8a515611384c2503ed6fbf1e5cb3dd7761769288c793b",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 13,
@ -629,8 +606,7 @@
"type": "snippet",
"attributes": {
"fileName": "grid-centering.md",
"text": "Horizontally and vertically centers a child element within a parent element using `grid`.\n\n",
"explanation": "\n\n- `display: grid` creates a grid layout\n- `justify-content: center` centers the child horizontally.\n- `align-items: center` centers the child vertically.\n",
"text": "Horizontally and vertically centers a child element within a parent element using `grid`.\n\n- `display: grid` creates a grid layout\n- `justify-content: center` centers the child horizontally.\n- `align-items: center` centers the child vertically.\n\n",
"codeBlocks": {
"html": "<div class=\"grid-centering\">\n <div class=\"child\">Centered content.</div>\n</div>",
"css": ".grid-centering {\n display: grid;\n justify-content: center;\n align-items: center;\n height: 100px;\n}",
@ -643,7 +619,7 @@
]
},
"meta": {
"hash": "f6607d84780e72310e7fab5b71b709bfb4cbfa3ece8cdd5447e151cef3a2eeb3",
"hash": "d857b58b1bba21639a95d1e703932d051b171bc890e6336b01ff25251a8fef3d",
"firstSeen": "1520072039",
"lastUpdated": "1588157277",
"updateCount": 14,
@ -656,8 +632,7 @@
"type": "snippet",
"attributes": {
"fileName": "hamburger-button.md",
"text": "Displays a hamburger menu which transitions to a cross on hover.\n\n",
"explanation": "\n\n- Use a `.hamburger-menu` container `div` which contains the top, bottom, and middle bars.\n- The container is set to be a flex container (`display: flex`) with `flex-direction` to be `column` and `flex-wrap` to be `wrap` (alternatively, you can set both properties by a shorthand `flex-flow: column wrap`).\n- Add distance between the bars using `justify-content: space-between`.\n- The animation has 3 parts: top and bottom bars transforming to 45 degree angles (`rotate(45deg)`), and the middle bar fading away by setting `opacity: 0`.\n- The `transform-origin` is set to `left` so the bars rotate around the left point.\n- Set `transition all 0.5s` so that both `transform` and `opacity` properties are animated for half a second.\n",
"text": "Displays a hamburger menu which transitions to a cross on hover.\n\n- Use a `.hamburger-menu` container `div` which contains the top, bottom, and middle bars.\n- The container is set to be a flex container (`display: flex`) with `flex-direction` to be `column` and `flex-wrap` to be `wrap` (alternatively, you can set both properties by a shorthand `flex-flow: column wrap`).\n- Add distance between the bars using `justify-content: space-between`.\n- The animation has 3 parts: top and bottom bars transforming to 45 degree angles (`rotate(45deg)`), and the middle bar fading away by setting `opacity: 0`.\n- The `transform-origin` is set to `left` so the bars rotate around the left point.\n- Set `transition all 0.5s` so that both `transform` and `opacity` properties are animated for half a second.\n\n",
"codeBlocks": {
"html": "<div class=\"hamburger-menu\">\n <div class=\"bar top\"></div>\n <div class=\"bar middle\"></div>\n <div class=\"bar bottom\"></div>\n</div>",
"css": ".hamburger-menu {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n justify-content: space-between;\n height: 2.5rem;\n width: 2.5rem;\n cursor: pointer;\n}\n\n.hamburger-menu .bar {\n height: 5px;\n background: black;\n border-radius: 5px;\n margin: 3px 0px;\n transform-origin: left;\n transition: all 0.5s;\n}\n\n.hamburger-menu:hover .top {\n transform: rotate(45deg);\n}\n\n.hamburger-menu:hover .middle {\n opacity: 0;\n}\n\n.hamburger-menu:hover .bottom {\n transform: rotate(-45deg);\n}",
@ -670,7 +645,7 @@
]
},
"meta": {
"hash": "deddca92aa1d97b54a0f711185e324142b785ddcbe747756a9bf7b6d861eef3a",
"hash": "a09fd36b831827cc4559103a91c31c660905786f072f9088914d39047076a2f5",
"firstSeen": "1570668578",
"lastUpdated": "1588157277",
"updateCount": 13,
@ -683,8 +658,7 @@
"type": "snippet",
"attributes": {
"fileName": "height-transition.md",
"text": "Transitions an element's height from `0` to `auto` when its height is unknown.\n\n",
"explanation": "\n\n- `transition: max-height: 0.5s cubic-bezier(...)` specifies that changes to `max-height` should be transitioned over 0.5 seconds, using an `ease-out-quint` timing function.\n- `overflow: hidden` prevents the contents of the hidden element from overflowing its container.\n- `max-height: 0` specifies that the element has no height initially.\n- `.target:hover > .el` specifies that when the parent is hovered over, target a child `.el` within it and use the `--max-height` variable which was defined by JavaScript.\n- `el.scrollHeight` is the height of the element including overflow, which will change dynamically based on the content of the element.\n- `el.style.setProperty(...)` sets the `--max-height` CSS variable which is used to specify the `max-height` of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.\n- Causes reflow on each animation frame, which will be laggy if there are a large number of elements beneath the element that is transitioning in height.\n",
"text": "Transitions an element's height from `0` to `auto` when its height is unknown.\n\n- `transition: max-height: 0.5s cubic-bezier(...)` specifies that changes to `max-height` should be transitioned over 0.5 seconds, using an `ease-out-quint` timing function.\n- `overflow: hidden` prevents the contents of the hidden element from overflowing its container.\n- `max-height: 0` specifies that the element has no height initially.\n- `.target:hover > .el` specifies that when the parent is hovered over, target a child `.el` within it and use the `--max-height` variable which was defined by JavaScript.\n- `el.scrollHeight` is the height of the element including overflow, which will change dynamically based on the content of the element.\n- `el.style.setProperty(...)` sets the `--max-height` CSS variable which is used to specify the `max-height` of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.\n- Causes reflow on each animation frame, which will be laggy if there are a large number of elements beneath the element that is transitioning in height.\n\n",
"codeBlocks": {
"html": "<div class=\"trigger\">\n Hover me to see a height transition.\n <div class=\"el\">Additional content</div>\n</div>",
"css": ".el {\n transition: max-height 0.5s;\n overflow: hidden;\n max-height: 0;\n}\n\n.trigger:hover > .el {\n max-height: var(--max-height);\n}",
@ -697,7 +671,7 @@
]
},
"meta": {
"hash": "5184cd3ad1c9a8d1cb05ddd5927af34e49727edf1dbf11bf49469c8a89758f0f",
"hash": "352f76bafa1970a885e0b9efaa3e7953bf4dfcebe4a62e745ee40312a85ef451",
"firstSeen": "1521276782",
"lastUpdated": "1588157277",
"updateCount": 14,
@ -710,8 +684,7 @@
"type": "snippet",
"attributes": {
"fileName": "hover-shadow-box-animation.md",
"text": "Creates a shadow box around the text when it is hovered.\n\n",
"explanation": "\n\n- `display: inline-block` to set width and length for `p` element thus making it an `inline-block`.\n- Set `transform: perspective(1px)` to give element a 3D space by affecting the distance between the Z plane and the user and `translate(0)` to reposition the `p` element along z-axis in 3D space.\n- `box-shadow:` to set up the box.\n- `transparent` to make box transparent.\n- `transition-property` to enable transitions for both `box-shadow` and `transform`.\n- `:hover` to activate whole css when hovering is done until `active`.\n- `transform: scale(1.2)` to change the scale, magnifying the text.\n",
"text": "Creates a shadow box around the text when it is hovered.\n\n- `display: inline-block` to set width and length for `p` element thus making it an `inline-block`.\n- Set `transform: perspective(1px)` to give element a 3D space by affecting the distance between the Z plane and the user and `translate(0)` to reposition the `p` element along z-axis in 3D space.\n- `box-shadow:` to set up the box.\n- `transparent` to make box transparent.\n- `transition-property` to enable transitions for both `box-shadow` and `transform`.\n- `:hover` to activate whole css when hovering is done until `active`.\n- `transform: scale(1.2)` to change the scale, magnifying the text.\n\n",
"codeBlocks": {
"html": "<p class=\"hover-shadow-box-animation\">Box it!</p>",
"css": ".hover-shadow-box-animation {\n display: inline-block;\n vertical-align: middle;\n transform: perspective(1px) translateZ(0);\n box-shadow: 0 0 1px transparent;\n margin: 10px;\n transition-duration: 0.3s;\n transition-property: box-shadow, transform;\n}\n\n.hover-shadow-box-animation:hover,\n.hover-shadow-box-animation:focus,\n.hover-shadow-box-animation:active {\n box-shadow: 1px 10px 10px -10px rgba(0, 0, 24, 0.5);\n transform: scale(1.2);\n}",
@ -724,7 +697,7 @@
]
},
"meta": {
"hash": "eabc2d005a29ead4539ee4ef5c511ed86e0bc64ed1480d69dce23ae3b706f60f",
"hash": "bb8dfca5ec4ded4fc4ddab56b3ade3b40d8b308eb66e866d89c64d9144fd3310",
"firstSeen": "1520372515",
"lastUpdated": "1588157277",
"updateCount": 19,
@ -737,8 +710,7 @@
"type": "snippet",
"attributes": {
"fileName": "hover-underline-animation.md",
"text": "Creates an animated underline effect when the text is hovered over.\n\n",
"explanation": "\n\n- `display: inline-block` makes the block `p` an `inline-block` to prevent the underline from spanning the entire parent width rather than just the content (text).\n- `position: relative` on the element establishes a Cartesian positioning context for pseudo-elements.\n- `:after` defines a pseudo-element.\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 100%` ensures the pseudo-element spans the entire width of the text block.\n- `transform: scaleX(0)` initially scales the pseudo element to 0 so it has no width and is not visible.\n- `bottom: 0` and `left: 0` position it to the bottom left of the block.\n- `transition: transform 0.25s ease-out` means changes to `transform` will be transitioned over 0.25 seconds with an `ease-out` timing function.\n- `transform-origin: bottom right` means the transform anchor point is positioned at the bottom right of the block.\n- `:hover:after` then uses `scaleX(1)` to transition the width to 100%, then changes the `transform-origin` to `bottom left` so that the anchor point is reversed, allowing it transition out in the other direction when hovered off.\n",
"text": "Creates an animated underline effect when the text is hovered over.\n\n- `display: inline-block` makes the block `p` an `inline-block` to prevent the underline from spanning the entire parent width rather than just the content (text).\n- `position: relative` on the element establishes a Cartesian positioning context for pseudo-elements.\n- `:after` defines a pseudo-element.\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 100%` ensures the pseudo-element spans the entire width of the text block.\n- `transform: scaleX(0)` initially scales the pseudo element to 0 so it has no width and is not visible.\n- `bottom: 0` and `left: 0` position it to the bottom left of the block.\n- `transition: transform 0.25s ease-out` means changes to `transform` will be transitioned over 0.25 seconds with an `ease-out` timing function.\n- `transform-origin: bottom right` means the transform anchor point is positioned at the bottom right of the block.\n- `:hover:after` then uses `scaleX(1)` to transition the width to 100%, then changes the `transform-origin` to `bottom left` so that the anchor point is reversed, allowing it transition out in the other direction when hovered off.\n\n",
"codeBlocks": {
"html": "<p class=\"hover-underline-animation\">Hover this text to see the effect!</p>",
"css": ".hover-underline-animation {\n display: inline-block;\n position: relative;\n color: #0087ca;\n}\n\n.hover-underline-animation:after {\n content: '';\n position: absolute;\n width: 100%;\n transform: scaleX(0);\n height: 2px;\n bottom: 0;\n left: 0;\n background-color: #0087ca;\n transform-origin: bottom right;\n transition: transform 0.25s ease-out;\n}\n\n.hover-underline-animation:hover:after {\n transform: scaleX(1);\n transform-origin: bottom left;\n}",
@ -751,7 +723,7 @@
]
},
"meta": {
"hash": "0478f301d7055ab1d351cf38ed9a2ae4410bc5ad62c9f5304bf58184174e5ee1",
"hash": "173fd77743be7ce3165e21ccc61d1893280230a03ccaac161f79349e8fdbaf2e",
"firstSeen": "1519816762",
"lastUpdated": "1588157277",
"updateCount": 19,
@ -764,8 +736,7 @@
"type": "snippet",
"attributes": {
"fileName": "image-hover-menu.md",
"text": "Displays a menu overlay when the image is hovered.\n\n",
"explanation": "\n\n- Use a `figure` to wrap the `img` element and a `div` element that will contain the menu links.\n- Use the `opacity` and `right` attributes to animate the image on hover, to create a sliding effect.\n- Set the `left` attribute of the `div` to the negative of the element's `width` and reset it to `0` when hovering over the parent element to slide in the menu.\n- Use `display: flex`, `flex-direction: column` and `justify-content: center` on the `div` to vertically center the menu items.\n",
"text": "Displays a menu overlay when the image is hovered.\n\n- Use a `figure` to wrap the `img` element and a `div` element that will contain the menu links.\n- Use the `opacity` and `right` attributes to animate the image on hover, to create a sliding effect.\n- Set the `left` attribute of the `div` to the negative of the element's `width` and reset it to `0` when hovering over the parent element to slide in the menu.\n- Use `display: flex`, `flex-direction: column` and `justify-content: center` on the `div` to vertically center the menu items.\n\n",
"codeBlocks": {
"html": "<figure class=\"hover-menu\">\n\t<img src=\"https://i.picsum.photos/id/1060/800/480.jpg\"/>\n\t<div>\n\t\t<a href=\"#\">Home</a>\n\t\t<a href=\"#\">Pricing</a>\n\t\t<a href=\"#\">About</a>\n\t</div>\n</figure>",
"css": ".hover-menu {\n position: relative;\n overflow: hidden;\n margin: 8px;\n min-width: 340px;\n max-width: 480px;\n max-height: 290px;\n width: 100%;\n background: #000;\n text-align: center;\n box-sizing: border-box;\n}\n\n.hover-menu * {\n box-sizing: border-box;\n}\n\n.hover-menu img {\n position: relative;\n max-width: 100%;\n top: 0;\n right: 0;\n opacity: 1;\n transition: 0.3s ease-in-out;\n}\n\n.hover-menu div {\n position: absolute;\n top: 0;\n left: -120px;\n width: 120px;\n height: 100%;\n padding: 8px 4px;\n background: #000;\n transition: 0.3s ease-in-out;\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n\n.hover-menu div a {\n display: block;\n line-height: 2;\n color: #fff;\n text-decoration: none;\n opacity: 0.8;\n padding: 5px 15px;\n position: relative;\n transition: 0.3s ease-in-out;\n}\n\n.hover-menu div a:hover {\n text-decoration: underline;\n}\n\n.hover-menu:hover img {\n opacity: 0.5;\n right: -120px;\n}\n\n.hover-menu:hover div {\n left: 0;\n opacity: 1;\n}",
@ -779,7 +750,7 @@
]
},
"meta": {
"hash": "4d1de01babf0eb96904aa9e7d130771ce3eebb82de60ffd22528ec635e0e8f27",
"hash": "8d6b871707a71474f7f3a0078d0d26b9805bf687983b71bfe1e623e6f9e76fb6",
"firstSeen": "1587399311",
"lastUpdated": "1588157277",
"updateCount": 3,
@ -792,8 +763,7 @@
"type": "snippet",
"attributes": {
"fileName": "image-hover-rotate.md",
"text": "Creates a rotate effect for the image on hover.\n\n",
"explanation": "\n\n- Use `scale` and `rotate` when hovering over the parent element (a `figure`) to animate the image, using the `transition` property.\n- Use `overflow: hidden` on the parent container to hide the excess from the image transformation.\n",
"text": "Creates a rotate effect for the image on hover.\n\n- Use `scale` and `rotate` when hovering over the parent element (a `figure`) to animate the image, using the `transition` property.\n- Use `overflow: hidden` on the parent container to hide the excess from the image transformation.\n\n",
"codeBlocks": {
"html": "<figure class=\"hover-rotate\">\n <img src=\"https://i.picsum.photos/id/669/600/800.jpg\"/>\n</figure>",
"css": ".hover-rotate {\n overflow: hidden;\n margin: 8px;\n min-width: 240px;\n max-width: 320px;\n width: 100%;\n}\n\n.hover-rotate img {\n transition: all 0.3s;\n box-sizing: border-box;\n max-width: 100%;\n}\n\n.hover-rotate:hover img {\n transform: scale(1.3) rotate(5deg);\n}",
@ -807,7 +777,7 @@
]
},
"meta": {
"hash": "dc4902b08c2cdd9808fa205054d7a63c5c2f2481fd138cd6d6b0fc6a4d9567fb",
"hash": "d523b90a983222ec07c1414306054e5f82019848b2f0ad0606e120f09114dfde",
"firstSeen": "1587396971",
"lastUpdated": "1588157277",
"updateCount": 3,
@ -820,8 +790,7 @@
"type": "snippet",
"attributes": {
"fileName": "image-overlay-hover.md",
"text": "Displays an image overlay effect on hover.\n\n",
"explanation": "\n\n- Use the `:before` and `:after` elements for the top and bottom bars of the overlay respectively, setting their `opacity`, `transform` and `transition` to produce the desired effect.\n- Use the `figcaption` for the text of the overlay, setting `display: flex`, `flex-direction: column` and `justify-content: center` to center the text into the image.\n- Use the `:hover` pseudo-selector to update the `opacity` and `transform` of all the elements and produce the desired effect.\n",
"text": "Displays an image overlay effect on hover.\n\n- Use the `:before` and `:after` elements for the top and bottom bars of the overlay respectively, setting their `opacity`, `transform` and `transition` to produce the desired effect.\n- Use the `figcaption` for the text of the overlay, setting `display: flex`, `flex-direction: column` and `justify-content: center` to center the text into the image.\n- Use the `:hover` pseudo-selector to update the `opacity` and `transform` of all the elements and produce the desired effect.\n\n",
"codeBlocks": {
"html": "<figure class=\"hover-img\">\n <img src=\"https://i.picsum.photos/id/200/440/320.jpg\"/>\n <figcaption>\n <h3>Lorem <br/>Ipsum</h3>\n </figcaption>\n</figure>",
"css": ".hover-img {\n background-color: #000;\n color: #fff;\n display: inline-block;\n margin: 8px;\n max-width: 320px;\n min-width: 240px;\n overflow: hidden;\n position: relative;\n text-align: center;\n width: 100%;\n}\n\n.hover-img * {\n box-sizing: border-box;\n transition: all 0.45s ease;\n}\n\n.hover-img:before,\n.hover-img:after {\n background-color: rgba(0, 0, 0, 0.5);\n border-top: 32px solid rgba(0, 0, 0, 0.5);\n border-bottom: 32px solid rgba(0, 0, 0, 0.5);\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n content: '';\n transition: all 0.3s ease;\n z-index: 1;\n opacity: 0;\n transform: scaleY(2);\n}\n\n.hover-img img {\n vertical-align: top;\n max-width: 100%;\n backface-visibility: hidden;\n}\n\n.hover-img figcaption {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n align-items: center;\n z-index: 1;\n display: flex;\n flex-direction: column;\n justify-content: center;\n line-height: 1.1em;\n opacity: 0;\n z-index: 2;\n transition-delay: 0.1s;\n font-size: 24px;\n font-family: sans-serif;\n font-weight: 400;\n letter-spacing: 1px;\n text-transform: uppercase;\n}\n\n.hover-img:hover:before,\n.hover-img:hover:after {\n transform: scale(1);\n opacity: 1;\n}\n\n.hover-img:hover > img {\n opacity: 0.7;\n}\n\n.hover-img:hover figcaption {\n opacity: 1;\n}",
@ -835,7 +804,7 @@
]
},
"meta": {
"hash": "4b81f4075b6dd65ae3ac592b3937e97185ae91a9ade04e90fe8a2d29ec9a9563",
"hash": "fc19dfe3f3e46a9d96f1d657ac304497a603f2176fe55960a2b0c59ea7bf0841",
"firstSeen": "1587381153",
"lastUpdated": "1588157277",
"updateCount": 3,
@ -848,8 +817,7 @@
"type": "snippet",
"attributes": {
"fileName": "masonry-layout.md",
"text": "Creates a vertical masonry layout using HTML and CSS.\n\n",
"explanation": "\n\n- Create a masonry-style layout that consists of \"bricks\" that fall into each other with either a fixed `width` (vertical layout) or a fixed `height` (horizontal layout), forming a perfect fit. Especially useful when working with images.\n- `.masonry-container` is the container for the masonry layout. Within that container, there's a `div.masonry-columns`, which will automatically put each child element, `.masonry-brick`, into the layout.\n- `.masonry-brick` must be have `display: block` to allow the layout to flow properly, while the `:first-child` of this class should have a different `margin` to account for its positioning.\n- CSS variables are used to allow for greater flexibility for the layout, while media queries ensure that the layout flows responsively in different viewport sizes.\n",
"text": "Creates a vertical masonry layout using HTML and CSS.\n\n- Create a masonry-style layout that consists of \"bricks\" that fall into each other with either a fixed `width` (vertical layout) or a fixed `height` (horizontal layout), forming a perfect fit. Especially useful when working with images.\n- `.masonry-container` is the container for the masonry layout. Within that container, there's a `div.masonry-columns`, which will automatically put each child element, `.masonry-brick`, into the layout.\n- `.masonry-brick` must be have `display: block` to allow the layout to flow properly, while the `:first-child` of this class should have a different `margin` to account for its positioning.\n- CSS variables are used to allow for greater flexibility for the layout, while media queries ensure that the layout flows responsively in different viewport sizes.\n\n",
"codeBlocks": {
"html": "<div class=\"masonry-container\">\n <div class=\"masonry-columns\">\n <img class=\"masonry-brick\" src=\"https://picsum.photos/id/1016/384/256\" alt=\"An image\">\n <img class=\"masonry-brick\" src=\"https://picsum.photos/id/1025/495/330\" alt=\"Another image\">\n <img class=\"masonry-brick\" src=\"https://picsum.photos/id/1024/192/128\" alt=\"Another image\">\n <img class=\"masonry-brick\" src=\"https://picsum.photos/id/1028/518/345\" alt=\"One more image\">\n <img class=\"masonry-brick\" src=\"https://picsum.photos/id/1035/585/390\" alt=\"And another one\">\n <img class=\"masonry-brick\" src=\"https://picsum.photos/id/1074/384/216\" alt=\"Last one\">\n </div>\n</div>",
"css": "/* Container */\n.masonry-container {\n --column-count-small: 1;\n --column-count-medium: 2;\n --column-count-large: 3;\n --column-gap: 0.125rem;\n padding: var(--column-gap);\n}\n\n/* Columns */\n.masonry-columns {\n column-gap: var(--column-gap);\n column-count: var(--column-count-small);\n column-width: calc(1 / var(--column-count-small) * 100%);\n}\n\n@media only screen and (min-width: 640px) {\n .masonry-columns {\n column-count: var(--column-count-medium);\n column-width: calc(1 / var(--column-count-medium) * 100%);\n }\n}\n\n@media only screen and (min-width: 800px) {\n .masonry-columns {\n column-count: var(--column-count-large);\n column-width: calc(1 / var(--column-count-large) * 100%);\n }\n}\n\n/* Bricks */\n.masonry-brick {\n width: 100%;\n height: auto;\n margin: var(--column-gap) 0;\n display: block;\n}\n\n.masonry-brick:first-child {\n margin: 0 0 var(--column-gap);\n}",
@ -862,7 +830,7 @@
]
},
"meta": {
"hash": "d4f66b4445b89bb966eed1285915b5c126e65773901efd93be77241a35096c93",
"hash": "85ba6326696a47079383e3f8870b593c59d0efeb1ff12bc9ec2bc3d2de96eb2f",
"firstSeen": "1576023545",
"lastUpdated": "1588157277",
"updateCount": 9,
@ -875,8 +843,7 @@
"type": "snippet",
"attributes": {
"fileName": "mouse-cursor-gradient-tracking.md",
"text": "A hover effect where the gradient follows the mouse cursor.\n\n",
"explanation": "\n\n- `--x` and `--y` are used to track the position of the mouse on the button.\n- `--size` is used to keep modify of the gradient's dimensions.\n- `background: radial-gradient(circle closest-side, pink, transparent);` creates the gradient at the correct postion.\n",
"text": "A hover effect where the gradient follows the mouse cursor.\n\n- `--x` and `--y` are used to track the position of the mouse on the button.\n- `--size` is used to keep modify of the gradient's dimensions.\n- `background: radial-gradient(circle closest-side, pink, transparent);` creates the gradient at the correct postion.\n\n",
"codeBlocks": {
"html": "<button class=\"mouse-cursor-gradient-tracking\">\n <span>Hover me</span>\n</button>",
"css": ".mouse-cursor-gradient-tracking {\n position: relative;\n background: #7983ff;\n padding: 0.5rem 1rem;\n font-size: 1.2rem;\n border: none;\n color: white;\n cursor: pointer;\n outline: none;\n overflow: hidden;\n}\n\n.mouse-cursor-gradient-tracking span {\n position: relative;\n}\n\n.mouse-cursor-gradient-tracking:before {\n --size: 0;\n content: '';\n position: absolute;\n left: var(--x);\n top: var(--y);\n width: var(--size);\n height: var(--size);\n background: radial-gradient(circle closest-side, pink, transparent);\n transform: translate(-50%, -50%);\n transition: width 0.2s ease, height 0.2s ease;\n}\n\n.mouse-cursor-gradient-tracking:hover:before {\n --size: 200px;\n}",
@ -890,7 +857,7 @@
]
},
"meta": {
"hash": "18381f782d6b2626841181827fb8c46ef31c19c743dedb1616f8900a91ae2e93",
"hash": "5631f8dbb1f5099bc7cc73f8147b73f6512e4d8805586d7b317a1dd4ce85f60b",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 20,
@ -903,8 +870,7 @@
"type": "snippet",
"attributes": {
"fileName": "navigation-list-item-hover-and-focus-effect.md",
"text": "Fancy hover and focus effect at navigation items using transform CSS property.\n\n",
"explanation": "\n\n- Use the `:before` pseudo-element at the list item anchor to create a hover effect, hide it using `transform: scale(0)`.\n- Use the `:hover` and `:focus` pseudo-selectors to transition to `transform: scale(1)` and show the pseudo-element with its colored background.\n- Prevent the pseudo-element from covering the anchor element by using `z-index: -1`.\n",
"text": "Fancy hover and focus effect at navigation items using transform CSS property.\n\n- Use the `:before` pseudo-element at the list item anchor to create a hover effect, hide it using `transform: scale(0)`.\n- Use the `:hover` and `:focus` pseudo-selectors to transition to `transform: scale(1)` and show the pseudo-element with its colored background.\n- Prevent the pseudo-element from covering the anchor element by using `z-index: -1`.\n\n",
"codeBlocks": {
"html": "<nav class=\"hover-nav\">\n <ul>\n <li><a href=\"#\">Home</a></li>\n <li><a href=\"#\">About</a></li>\n <li><a href=\"#\">Contact</a></li>\n </ul>\n</nav>",
"css": ".hover-nav ul {\n list-style: none;\n margin: 0;\n padding: 0;\n overflow: hidden;\n}\n\n.hover-nav li {\n float: left;\n}\n\n.hover-nav li a {\n position: relative;\n display: block;\n color: #222;\n text-align: center;\n padding: 8px 12px;\n text-decoration: none;\n}\n\nli a:before {\n position: absolute;\n content: \"\";\n width: 100%;\n height: 100%;\n bottom: 0;\n left: 0;\n background-color: #f6c126;\n z-index: -1;\n transform: scale(0);\n transition: transform 0.5s ease-in-out;\n}\n\nli a:hover:before,\nli a:focus:before {\n transform: scale(1);\n}",
@ -917,7 +883,7 @@
]
},
"meta": {
"hash": "b370358743c0e9f3ff11bfa43a23a08a02b777617f02bbf1b35a33a9ad0dace4",
"hash": "a706f7ad219f80e4bb215d1d121f2e31770505bc05972c08dc5cd5dd62e263ec",
"firstSeen": "1568922537",
"lastUpdated": "1588157277",
"updateCount": 7,
@ -930,8 +896,7 @@
"type": "snippet",
"attributes": {
"fileName": "offscreen.md",
"text": "Completely hides an element visually and positionally in the DOM while still allowing it to be accessible.\nProvides an alternative to `display: none` (not readable by screen readers) and `visibility: hidden` (takes up physical space in the DOM).\n\n",
"explanation": "\n\n- Remove all borders.\n- Use `clip` to indicate that no part of the element should be shown.\n- Make the height and width of the element 1px.\n- Negate the elements height and width using `margin: -1px`.\n- Hide the element's overflow.\n- Remove all padding.\n- Position the element absolutely so that it does not take up space in the DOM.\n",
"text": "Completely hides an element visually and positionally in the DOM while still allowing it to be accessible.\nProvides an alternative to `display: none` (not readable by screen readers) and `visibility: hidden` (takes up physical space in the DOM).\n\n- Remove all borders.\n- Use `clip` to indicate that no part of the element should be shown.\n- Make the height and width of the element 1px.\n- Negate the elements height and width using `margin: -1px`.\n- Hide the element's overflow.\n- Remove all padding.\n- Position the element absolutely so that it does not take up space in the DOM.\n\n",
"codeBlocks": {
"html": "<a class=\"button\" href=\"https://google.com\">\n Learn More <span class=\"offscreen\"> about pants</span>\n</a>",
"css": ".offscreen {\n border: 0;\n clip: rect(0 0 0 0);\n height: 1px;\n margin: -1px;\n overflow: hidden;\n padding: 0;\n position: absolute;\n width: 1px;\n}",
@ -945,7 +910,7 @@
]
},
"meta": {
"hash": "7b1f889c040ecd46fa953ea639b896158e8dcfbc741837eda9980dbc7531c315",
"hash": "a90b3286ce3c589372d987059ec2a5403aaafdcc4eb117d8c714531d040f450b",
"firstSeen": "1522425031",
"lastUpdated": "1588157277",
"updateCount": 15,
@ -958,8 +923,7 @@
"type": "snippet",
"attributes": {
"fileName": "overflow-scroll-gradient.md",
"text": "Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled.\n\n",
"explanation": "\n\n- `position: relative` on the parent establishes a Cartesian positioning context for pseudo-elements.\n- `:after` defines a pseudo element.\n- `background-image: linear-gradient(...)` adds a linear gradient that fades from transparent to white (top to bottom).\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 240px` matches the size of the scrolling element (which is a child of the parent that has the pseudo element).\n- `height: 25px` is the height of the fading gradient pseudo-element, which should be kept relatively small.\n- `bottom: 0` positions the pseudo-element at the bottom of the parent.\n- `pointer-events: none` specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.\n",
"text": "Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled.\n\n- `position: relative` on the parent establishes a Cartesian positioning context for pseudo-elements.\n- `:after` defines a pseudo element.\n- `background-image: linear-gradient(...)` adds a linear gradient that fades from transparent to white (top to bottom).\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 240px` matches the size of the scrolling element (which is a child of the parent that has the pseudo element).\n- `height: 25px` is the height of the fading gradient pseudo-element, which should be kept relatively small.\n- `bottom: 0` positions the pseudo-element at the bottom of the parent.\n- `pointer-events: none` specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.\n\n",
"codeBlocks": {
"html": "<div class=\"overflow-scroll-gradient\">\n <div class=\"overflow-scroll-gradient-scroller\">\n Lorem ipsum dolor sit amet consectetur adipisicing elit. <br />\n Iure id exercitationem nulla qui repellat laborum vitae, <br />\n molestias tempora velit natus. Quas, assumenda nisi. <br />\n Quisquam enim qui iure, consequatur velit sit? <br />\n Lorem ipsum dolor sit amet consectetur adipisicing elit.<br />\n Iure id exercitationem nulla qui repellat laborum vitae, <br />\n molestias tempora velit natus. Quas, assumenda nisi. <br />\n Quisquam enim qui iure, consequatur velit sit?\n </div>\n</div>",
"css": ".overflow-scroll-gradient {\n position: relative;\n}\n\n.overflow-scroll-gradient:after {\n content: '';\n position: absolute;\n bottom: 0;\n width: 250px;\n height: 25px;\n background: linear-gradient(transparent, white);\n pointer-events: none;\n}\n\n.overflow-scroll-gradient-scroller {\n overflow-y: scroll;\n background: white;\n width: 240px;\n height: 200px;\n padding: 15px;\n line-height: 1.2;\n}",
@ -972,7 +936,7 @@
]
},
"meta": {
"hash": "40f97588c10b498c81d7aa4856749bd5fe81a0730125397de01cb0161b3e8ec5",
"hash": "bb535308605467e737fd227ebcb9652cc882cc4430d5390305a1dfa3d5d60064",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 21,
@ -985,8 +949,7 @@
"type": "snippet",
"attributes": {
"fileName": "popout-menu.md",
"text": "Reveals an interactive popout menu on hover and focus.\n\n",
"explanation": "\n\n- `position: relative` on the reference parent establishes a Cartesian positioning context for its child.\n- `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.\n- `left: 100%` moves the the popout menu 100% of its parent's width from the left.\n- `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).\n- `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.\n- `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.\n- `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is _within_ the reference.\n",
"text": "Reveals an interactive popout menu on hover and focus.\n\n- `position: relative` on the reference parent establishes a Cartesian positioning context for its child.\n- `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.\n- `left: 100%` moves the the popout menu 100% of its parent's width from the left.\n- `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).\n- `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.\n- `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.\n- `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is within the reference.\n\n",
"codeBlocks": {
"html": "<div class=\"reference\" tabindex=\"0\">\n <div class=\"popout-menu\">Popout menu</div>\n</div>",
"css": ".reference {\n position: relative;\n background: tomato;\n width: 100px;\n height: 80px;\n}\n\n.popout-menu {\n position: absolute;\n visibility: hidden;\n left: 100%;\n background: #333;\n color: white;\n padding: 16px;\n}\n\n.reference:hover > .popout-menu,\n.reference:focus > .popout-menu,\n.reference:focus-within > .popout-menu {\n visibility: visible;\n}",
@ -999,7 +962,7 @@
]
},
"meta": {
"hash": "eb2ec9e57d5c184b8d5a3c92c80f9525b1fb1d85e575048b07fdaebb5ae33fbd",
"hash": "d797cfbddfb71083bd0641014330f4fc2e9e88940c5e8f5250085acfc2aa639f",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 15,
@ -1012,8 +975,7 @@
"type": "snippet",
"attributes": {
"fileName": "pretty-text-underline.md",
"text": "A nicer alternative to `text-decoration: underline` where descenders do not clip the underline.\nNatively implemented as `text-decoration-skip-ink: auto` but it has less control over the underline.\n\n",
"explanation": "\n\n- `text-shadow` uses 4 values with offsets that cover a 4x4 px area to ensure the underline has a \"thick\" shadow that covers the line where descenders clip it. Use a color that matches the background. For a larger font, use a larger `px` size. Additional values can create an even thicker shadow, and subpixel values can also be used.\n- `background-image: linear-gradient(...)` creates a 90deg gradient using the text color (`currentColor`).\n- The `background-*` properties size the gradient as 100% of the width of the block and 1px in height at the bottom and disables repetition, which creates a 1px underline beneath the text.\n- The `::selection` pseudo selector rule ensures the text shadow does not interfere with text selection.\n",
"text": "A nicer alternative to `text-decoration: underline` where descenders do not clip the underline.\nNatively implemented as `text-decoration-skip-ink: auto` but it has less control over the underline.\n\n- `text-shadow` uses 4 values with offsets that cover a 4x4 px area to ensure the underline has a \"thick\" shadow that covers the line where descenders clip it. Use a color that matches the background. For a larger font, use a larger `px` size. Additional values can create an even thicker shadow, and subpixel values can also be used.\n- `background-image: linear-gradient(...)` creates a 90deg gradient using the text color (`currentColor`).\n- The `background-*` properties size the gradient as 100% of the width of the block and 1px in height at the bottom and disables repetition, which creates a 1px underline beneath the text.\n- The `::selection` pseudo selector rule ensures the text shadow does not interfere with text selection.\n\n",
"codeBlocks": {
"html": "<p class=\"pretty-text-underline\">Pretty text underline without clipping descenders.</p>",
"css": ".pretty-text-underline {\n display: inline;\n text-shadow: 1px 1px #f5f6f9, -1px 1px #f5f6f9, -1px -1px #f5f6f9, 1px -1px #f5f6f9;\n background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);\n background-position: bottom;\n background-repeat: no-repeat;\n background-size: 100% 1px;\n}\n\n.pretty-text-underline::-moz-selection {\n background-color: rgba(0, 150, 255, 0.3);\n text-shadow: none;\n}\n\n.pretty-text-underline::selection {\n background-color: rgba(0, 150, 255, 0.3);\n text-shadow: none;\n}",
@ -1026,7 +988,7 @@
]
},
"meta": {
"hash": "c557dfe07a810b84db11e686aff41b5873935cbc22d52aa65effbdca1c9fd221",
"hash": "58273d473de9ed1d5fea2cf29ab661cbd8a694bb73129a8045aecdcef417cab4",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 21,
@ -1039,8 +1001,7 @@
"type": "snippet",
"attributes": {
"fileName": "pulse-loader.md",
"text": "Creates a pulse effect loader animation using the `animation-delay` property.\n\n",
"explanation": "\n\n- Use `@keyframes` to define an animation at two points in the cycle, start (`0%`), where the two `<div>` elements have no `width` or `height` and are positioned at the center and end (`100%`), where both `<div>` elements have increased `width` and `height`, but their `position` is reset to `0`.\n- Use `opacity` to transition from `1` to `0` when animating to give the `<div>` elements a disappearing effect as they expand.\n- `.ripple-loader`, which is the parent container, has a predefined `width` and `height`. It uses `position: relative` to position its children.\n- Use `animation-delay` on the second `<div>` element, so that each element starts its animation at a different time.\n",
"text": "Creates a pulse effect loader animation using the `animation-delay` property.\n\n- Use `@keyframes` to define an animation at two points in the cycle, start (`0%`), where the two `<div>` elements have no `width` or `height` and are positioned at the center and end (`100%`), where both `<div>` elements have increased `width` and `height`, but their `position` is reset to `0`.\n- Use `opacity` to transition from `1` to `0` when animating to give the `<div>` elements a disappearing effect as they expand.\n- `.ripple-loader`, which is the parent container, has a predefined `width` and `height`. It uses `position: relative` to position its children.\n- Use `animation-delay` on the second `<div>` element, so that each element starts its animation at a different time.\n\n",
"codeBlocks": {
"html": "<div class=\"ripple-loader\">\n <div></div>\n <div></div>\n</div>",
"css": ".ripple-loader {\n position: relative;\n width: 64px;\n height: 64px;\n}\n\n.ripple-loader div {\n position: absolute;\n border: 4px solid #454ADE;\n border-radius: 50%;\n animation: ripple-loader 1s ease-out infinite;\n}\n\n.ripple-loader div:nth-child(2) {\n animation-delay: -0.5s;\n}\n\n@keyframes ripple-loader {\n 0% {\n top: 32px;\n left: 32px;\n width: 0;\n height: 0;\n opacity: 1;\n }\n 100% {\n top: 0;\n left: 0;\n width: 64px;\n height: 64px;\n opacity: 0;\n }\n}",
@ -1053,7 +1014,7 @@
]
},
"meta": {
"hash": "3fba44e965b1c277cce6acb2c0c1a8dc99a837f40030b449ebe67c0857a0a12a",
"hash": "09a2fcbf7d4d213681c6967c0af276b52847fe914e4ef4661bce4591bee62f82",
"firstSeen": "1570274976",
"lastUpdated": "1588157277",
"updateCount": 6,
@ -1066,8 +1027,7 @@
"type": "snippet",
"attributes": {
"fileName": "reset-all-styles.md",
"text": "Resets all styles to default values with one property. This will not affect `direction` and `unicode-bidi` properties.\n\n",
"explanation": "\n\n- The `all` property allows you to reset all styles (inherited or not) to default values.\n",
"text": "Resets all styles to default values with one property. This will not affect `direction` and `unicode-bidi` properties.\n\n- The `all` property allows you to reset all styles (inherited or not) to default values.\n\n",
"codeBlocks": {
"html": "<div class=\"reset-all-styles\">\n <h5>Title</h5>\n <p>\n Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui\n repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui\n iure, consequatur velit sit?\n </p>\n</div>",
"css": ".reset-all-styles {\n all: initial;\n}",
@ -1080,7 +1040,7 @@
]
},
"meta": {
"hash": "1813fd4a625a84837affff81507c12d410df6253d3d006fdd8213e349b3cf644",
"hash": "bae8c46439801982a671d5883d5d9b0a7c955e658dea931b657f52cc446a3cad",
"firstSeen": "1519847496",
"lastUpdated": "1588157277",
"updateCount": 15,
@ -1093,8 +1053,7 @@
"type": "snippet",
"attributes": {
"fileName": "shape-separator.md",
"text": "Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.\n\n",
"explanation": "\n\n- `position: relative` on the element establishes a Cartesian positioning context for pseudo elements.\n- `:after` defines a pseudo element.\n- `background-image: url(...)` adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use [the URL-encoder for SVG](http://yoksel.github.io/url-encoder/).\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 100%` ensures the element stretches the entire width of its parent.\n- `height: 12px` is the same height as the shape.\n- `bottom: 0` positions the pseudo element at the bottom of the parent.\n",
"text": "Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.\n\n- `position: relative` on the element establishes a Cartesian positioning context for pseudo elements.\n- `:after` defines a pseudo element.\n- `background-image: url(...)` adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use [the URL-encoder for SVG](http://yoksel.github.io/url-encoder/).\n- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n- `width: 100%` ensures the element stretches the entire width of its parent.\n- `height: 12px` is the same height as the shape.\n- `bottom: 0` positions the pseudo element at the bottom of the parent.\n\n",
"codeBlocks": {
"html": "<div class=\"shape-separator\"></div>",
"css": ".shape-separator {\n position: relative;\n height: 48px;\n background: #333;\n}\n\n.shape-separator:after {\n content: '';\n background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 12'%3E%3Cpath d='m12 0l12 12h-24z' fill='%23fff'/%3E%3C/svg%3E\");\n position: absolute;\n width: 100%;\n height: 12px;\n bottom: 0;\n}",
@ -1107,7 +1066,7 @@
]
},
"meta": {
"hash": "b8948776d4ef4e58231d674dc0cff8b471e393713720b126282e4f6331a15283",
"hash": "8c985301a6849e17ef6daef42a24687186f1d82392f8897bf55cb87591322a77",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 16,
@ -1120,8 +1079,7 @@
"type": "snippet",
"attributes": {
"fileName": "sibling-fade.md",
"text": "Fades out the siblings of a hovered item.\n\n",
"explanation": "\n\n- `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.3 seconds.\n- `.sibling-fade:hover span:not(:hover)` specifies that when the parent is hovered, select any `span` children that are not currently being hovered and change their opacity to `0.5`.\n",
"text": "Fades out the siblings of a hovered item.\n\n- `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.3 seconds.\n- `.sibling-fade:hover span:not(:hover)` specifies that when the parent is hovered, select any `span` children that are not currently being hovered and change their opacity to `0.5`.\n\n",
"codeBlocks": {
"html": "<div class=\"sibling-fade\">\n <span>Item 1</span> <span>Item 2</span> <span>Item 3</span> <span>Item 4</span>\n <span>Item 5</span> <span>Item 6</span>\n</div>",
"css": "span {\n padding: 0 1rem;\n transition: opacity 0.3s;\n}\n\n.sibling-fade:hover span:not(:hover) {\n opacity: 0.5;\n}",
@ -1134,7 +1092,7 @@
]
},
"meta": {
"hash": "edfb001e96eb8756f8f74d2c12874fe4939a296b9af48fe67aee6b78493287f2",
"hash": "f1109f442664a97d322654608b8bb7b8aed1a5c9f3634608f5ed443d91200f1a",
"firstSeen": "1520237843",
"lastUpdated": "1588157277",
"updateCount": 15,
@ -1147,8 +1105,7 @@
"type": "snippet",
"attributes": {
"fileName": "staggered-animation.md",
"text": "Creates a staggered animation for the elements of a list.\n\n",
"explanation": "\n\n- Set the `opacity` to `0` and `transform` to `translateX(100%)` to make list elements transparent and move them all the way to the right.\n- Specify the appropriate `transition` properties for list elements, except `transition-delay` which is specified relative to the `--i` custom property.\n- Use inline styles to specify a value for `--i` for each list element, which will in turn be used for `transition-delay` to create the stagger effect.\n- Use the `:checked` selector for the checkbox to appropriately style list elements, setting `opacity` to `1` and `transform` to `translateX(0)` to make them appear and slide into view.\n",
"text": "Creates a staggered animation for the elements of a list.\n\n- Set the `opacity` to `0` and `transform` to `translateX(100%)` to make list elements transparent and move them all the way to the right.\n- Specify the appropriate `transition` properties for list elements, except `transition-delay` which is specified relative to the `--i` custom property.\n- Use inline styles to specify a value for `--i` for each list element, which will in turn be used for `transition-delay` to create the stagger effect.\n- Use the `:checked` selector for the checkbox to appropriately style list elements, setting `opacity` to `1` and `transform` to `translateX(0)` to make them appear and slide into view.\n\n",
"codeBlocks": {
"html": "<div class=\"container\">\n <input type=\"checkbox\" name=\"menu\" id=\"menu\" class=\"menu-toggler\">\n <label for=\"menu\" class=\"menu-toggler-label\">Menu</label>\n <ul class=\"stagger-menu\">\n <li style=\"--i: 0\">Home</li>\n <li style=\"--i: 1\">Pricing</li>\n <li style=\"--i: 2\">Account</li>\n <li style=\"--i: 3\">Support</li>\n <li style=\"--i: 4\">About</li>\n </ul>\n</div>",
"css": ".container {\n overflow-x: hidden;\n width: 100%;\n}\n\n.menu-toggler {\n display: none;\n}\n\n.menu-toggler-label {\n cursor: pointer;\n font-size: 20px;\n font-weight: bold;\n}\n\n.stagger-menu {\n list-style-type: none;\n margin: 16px 0;\n padding: 0;\n}\n\n.stagger-menu li {\n margin-bottom: 8px;\n font-size: 18px;\n opacity: 0;\n transform: translateX(100%);\n transition-property: opacity, transform;\n transition-duration: 0.3s;\n transition-timing-function: cubic-bezier(0.750, -0.015, 0.565, 1.055);\n}\n\n.menu-toggler:checked ~ .stagger-menu li {\n opacity: 1;\n transform: translateX(0);\n transition-delay: calc(0.055s * var(--i));\n}",
@ -1161,7 +1118,7 @@
]
},
"meta": {
"hash": "ba42b3a628a75b1e0821a3545addee0d93268827d74ffb319853cb136b227ae0",
"hash": "0d558f8f243a9eb6d225a5d600002b36d425e16edcc4f1baf2583965baddab5d",
"firstSeen": "1584353945",
"lastUpdated": "1588157277",
"updateCount": 3,
@ -1174,8 +1131,7 @@
"type": "snippet",
"attributes": {
"fileName": "system-font-stack.md",
"text": "Uses the native font of the operating system to get close to a native app feel.\n\n",
"explanation": "\n\nThe browser looks for each successive font, preferring the first one if possible, and falls back to the next if it cannot find the font (on the system or defined in CSS).\n\n- `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however)\n- `BlinkMacSystemFont` is San Francisco, used on macOS Chrome\n- `Segoe UI` is used on Windows 10\n- `Roboto` is used on Android\n- `Oxygen-Sans` is used on Linux with KDE\n- `Ubuntu` is used on Ubuntu (all variants)\n- `Cantarell` is used on Linux with GNOME Shell\n- `\"Helvetica Neue\"` and `Helvetica` is used on macOS 10.10 and below (wrapped in quotes because it has a space)\n- `Arial` is a font widely supported by all operating systems\n- `sans-serif` is the fallback sans-serif font if none of the other fonts are supported\n",
"text": "Uses the native font of the operating system to get close to a native app feel.\n\n- The browser looks for each successive font, preferring the first one if possible, and falls back to the next if it cannot find the font (on the system or defined in CSS).\n- `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however).\n- `BlinkMacSystemFont` is San Francisco, used on macOS Chrome.\n- `Segoe UI` is used on Windows 10.\n- `Roboto` is used on Android.\n- `Oxygen-Sans` is used on Linux with KDE.\n- `Ubuntu` is used on Ubuntu (all variants).\n- `Cantarell` is used on Linux with GNOME Shell.\n- `\"Helvetica Neue\"` and `Helvetica` is used on macOS 10.10 and below (wrapped in quotes because it has a space).\n- `Arial` is a font widely supported by all operating systems.\n- `sans-serif` is the fallback sans-serif font if none of the other fonts are supported.\n\n",
"codeBlocks": {
"html": "<p class=\"system-font-stack\">This text uses the system font.</p>",
"css": ".system-font-stack {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu,\n Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;\n}",
@ -1188,7 +1144,7 @@
]
},
"meta": {
"hash": "7f3f5475cd1f943bd0fe9c2458e191fc11635c21dbdd1067b01bf1734e834693",
"hash": "72972deca6938ab71aa1fb99bf907290ad85f6388d348308772fbebf302be920",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 15,
@ -1201,8 +1157,7 @@
"type": "snippet",
"attributes": {
"fileName": "tile-layout-using-inline-block.md",
"text": "Align items horizontally using `display: inline-block` to create a 3-tile layout.\n\n",
"explanation": "\n\n- Use `display: inline-block` to create a tiled layout, without using `float`, `flex` or `grid`.\n- `.tiles` is the container component, `.tile` is an item that needs to be displayed inline.\n- Use `width: calc((900px / 3))` to divide the width of the container evenly into 3 columns.\n- Set `font-size: 0;` on `.tiles` to avoid whitespace.\n- Set `font-size: 20px` to `h2` in order to display the text.\n",
"text": "Align items horizontally using `display: inline-block` to create a 3-tile layout.\n\n- Use `display: inline-block` to create a tiled layout, without using `float`, `flex` or `grid`.\n- `.tiles` is the container component, `.tile` is an item that needs to be displayed inline.\n- Use `width: calc((900px / 3))` to divide the width of the container evenly into 3 columns.\n- Set `font-size: 0;` on `.tiles` to avoid whitespace.\n- Set `font-size: 20px` to `h2` in order to display the text.\n\n",
"codeBlocks": {
"html": "<div class=\"tiles\">\n <div class=\"tile\">\n <img src=\"https://via.placeholder.com/200x150\">\n <h2>30 Seconds of CSS</h2>\n </div>\n <div class=\"tile\">\n <img src=\"https://via.placeholder.com/200x150\">\n <h2>30 Seconds of CSS</h2>\n </div>\n <div class=\"tile\">\n <img src=\"https://via.placeholder.com/200x150\">\n <h2>30 Seconds of CSS</h2>\n </div>\n</div>",
"css": ".tiles {\n width: 600px;\n font-size: 0;\n margin: 0 auto;\n}\n\n.tile {\n width: calc(600px / 3);\n display: inline-block;\n}\n\n.tile h2 {\n font-size: 20px;\n}",
@ -1215,7 +1170,7 @@
]
},
"meta": {
"hash": "c62825a3dd87c5b2f3197f085e1d90f81b16f0c3b1e2fe0ccf2ce18c39791954",
"hash": "3f6dc841d9c09dc46e7e03181db7ca3d1096cdd6146cc4727c0787116f691b88",
"firstSeen": "1569999119",
"lastUpdated": "1588157277",
"updateCount": 4,
@ -1228,8 +1183,7 @@
"type": "snippet",
"attributes": {
"fileName": "toggle-switch.md",
"text": "Creates a toggle switch with CSS only.\n\n",
"explanation": "\n\nThis effect is styling only the `<label>` element to look like a toggle switch, and hiding the actual `<input>` checkbox by positioning it offscreen. When clicking the label associated with the `<input>` element, it sets the `<input>` checkbox into the `:checked` state.\n\n- The `for` attribute associates the `<label>` with the appropriate `<input>` checkbox element by its `id`.\n- `.switch:after` defines a pseudo-element for the `<label>` to create the circular knob.\n- `input[type='checkbox']:checked + .switch:after` targets the `<label>`'s pseudo-element's style when the checkbox is `checked`.\n- `transform: translateX(20px)` moves the pseudo-element (knob) 20px to the right when the checkbox is `checked`.\n- `background-color: #7983ff;` sets the background-color of the switch to a different color when the checkbox is `checked`.\n- `.offscreen` moves the `<input>` checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it is accessible via keyboard and screen readers.\n- `transition: all 0.3s` specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the `<label>`'s `background-color` and the pseudo-element's `transform` property when the checkbox is checked.\n",
"text": "Creates a toggle switch with CSS only.\n\n- This effect is styling only the `<label>` element to look like a toggle switch, and hiding the actual `<input>` checkbox by positioning it offscreen. When clicking the label associated with the `<input>` element, it sets the `<input>` checkbox into the `:checked` state.\n- The `for` attribute associates the `<label>` with the appropriate `<input>` checkbox element by its `id`.\n- `.switch:after` defines a pseudo-element for the `<label>` to create the circular knob.\n- `input[type='checkbox']:checked + .switch:after` targets the `<label>`'s pseudo-element's style when the checkbox is `checked`.\n- `transform: translateX(20px)` moves the pseudo-element (knob) 20px to the right when the checkbox is `checked`.\n- `background-color: #7983ff;` sets the background-color of the switch to a different color when the checkbox is `checked`.\n- `.offscreen` moves the `<input>` checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it is accessible via keyboard and screen readers.\n- `transition: all 0.3s` specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the `<label>`'s `background-color` and the pseudo-element's `transform` property when the checkbox is checked.\n\n",
"codeBlocks": {
"html": "<input type=\"checkbox\" id=\"toggle\" class=\"offscreen\" /> <label for=\"toggle\" class=\"switch\"></label>",
"css": ".switch {\n position: relative;\n display: inline-block;\n width: 40px;\n height: 20px;\n background-color: rgba(0, 0, 0, 0.25);\n border-radius: 20px;\n transition: all 0.3s;\n}\n\n.switch:after {\n content: '';\n position: absolute;\n width: 18px;\n height: 18px;\n border-radius: 18px;\n background-color: white;\n top: 1px;\n left: 1px;\n transition: all 0.3s;\n}\n\ninput[type='checkbox']:checked + .switch:after {\n transform: translateX(20px);\n}\n\ninput[type='checkbox']:checked + .switch {\n background-color: #7983ff;\n}\n\n.offscreen {\n position: absolute;\n left: -9999px;\n}",
@ -1243,7 +1197,7 @@
]
},
"meta": {
"hash": "88ff8aa83e0245ae116894838571faa4cf3641b3a88b3f79d4322191bce84091",
"hash": "f249c8f58589c89bee1864f2e1f52289d55001c3aa1bcc7da63766da8d039837",
"firstSeen": "1538546120",
"lastUpdated": "1588157277",
"updateCount": 13,
@ -1256,8 +1210,7 @@
"type": "snippet",
"attributes": {
"fileName": "transform-centering.md",
"text": "Vertically and horizontally centers a child element within its parent element using `position: absolute` and `transform: translate()` (as an alternative to `flexbox` or `display: table`). Similar to `flexbox`, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.\n\n",
"explanation": "\n\n- `position: absolute` on the child element allows it to be positioned based on its containing block.\n- `left: 50%` and `top: 50%` offsets the child 50% from the left and top edge of its containing block.\n- `transform: translate(-50%, -50%)` allows the height and width of the child element to be negated so that it is vertically and horizontally centered.\n- Note that the fixed height and width on parent element is for the demo only.\n",
"text": "Vertically and horizontally centers a child element within its parent element using `position: absolute` and `transform: translate()` (as an alternative to `flexbox` or `display: table`).\nSimilar to `flexbox`, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.\n\n- `position: absolute` on the child element allows it to be positioned based on its containing block.\n- `left: 50%` and `top: 50%` offsets the child 50% from the left and top edge of its containing block.\n- `transform: translate(-50%, -50%)` allows the height and width of the child element to be negated so that it is vertically and horizontally centered.\n- Note that the fixed height and width on parent element is for the demo only.\n\n",
"codeBlocks": {
"html": "<div class=\"parent\">\n <div class=\"child\">Centered content</div>\n</div>",
"css": ".parent {\n border: 1px solid #333;\n height: 250px;\n position: relative;\n width: 250px;\n}\n\n.child {\n left: 50%;\n position: absolute;\n top: 50%;\n transform: translate(-50%, -50%);\n text-align: center;\n}",
@ -1270,7 +1223,7 @@
]
},
"meta": {
"hash": "efbaa2a999b1bc85faea000ca9a04c4e66d7b41b215c8752068f10c3f194da08",
"hash": "0ad151713b3074cad6ac930a7ffd48c3b4506a5f208be278ac7d3fde857e7ae6",
"firstSeen": "1522421968",
"lastUpdated": "1588157277",
"updateCount": 16,
@ -1283,8 +1236,7 @@
"type": "snippet",
"attributes": {
"fileName": "triangle.md",
"text": "Creates a triangle shape with pure CSS.\n\n",
"explanation": "\n\n- The color of the border is the color of the triangle. The side the triangle tip points corresponds to the opposite `border-*` property. For example, a color on `border-top` means the arrow points downward.\n- Experiment with the `px` values to change the proportion of the triangle.\n",
"text": "Creates a triangle shape with pure CSS.\n\n- The color of the border is the color of the triangle. The side the triangle tip points corresponds to the opposite `border-*` property. For example, a color on `border-top` means the arrow points downward.\n- Experiment with the `px` values to change the proportion of the triangle.\n\n",
"codeBlocks": {
"html": "<div class=\"triangle\"></div>",
"css": ".triangle {\n width: 0;\n height: 0;\n border-top: 20px solid #333;\n border-left: 20px solid transparent;\n border-right: 20px solid transparent;\n}",
@ -1297,7 +1249,7 @@
]
},
"meta": {
"hash": "a7ad6f6b9af62bf54cfec688bed9e2a3ce3519fd8ce7c2710705a87b99e9091b",
"hash": "0b6e42e3690d7573c164adfd341bcb3b53688fe073a56f16b3acc3a780fa8074",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 12,
@ -1310,8 +1262,7 @@
"type": "snippet",
"attributes": {
"fileName": "truncate-text-multiline.md",
"text": "If the text is longer than one line, it will be truncated for `n` lines and end with an gradient fade.\n\n",
"explanation": "\n\n- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).\n- `width: 400px` ensures the element has a dimension.\n- `height: 109.2px` calculated value for height, it equals `font-size * line-height * numberOfLines` (in this case `26 * 1.4 * 3 = 109.2`)\n- `height: 36.4px` calculated value for gradient container, it equals `font-size * line-height` (in this case `26 * 1.4 = 36.4`)\n- `background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%)` gradient from `transparent` to `#f5f6f9`\n",
"text": "If the text is longer than one line, it will be truncated for `n` lines and end with an gradient fade.\n\n- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).\n- `width: 400px` ensures the element has a dimension.\n- `height: 109.2px` calculated value for height, it equals `font-size * line-height * numberOfLines` (in this case `26 * 1.4 * 3 = 109.2`).\n- `height: 36.4px` calculated value for gradient container, it equals `font-size * line-height` (in this case `26 * 1.4 = 36.4`).\n- `background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%)` gradient from `transparent` to `#f5f6f9`.\n\n",
"codeBlocks": {
"html": "<p class=\"truncate-text-multiline\">\n Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut\n labore et.\n</p>",
"css": ".truncate-text-multiline {\n overflow: hidden;\n display: block;\n height: 109.2px;\n margin: 0 auto;\n font-size: 26px;\n line-height: 1.4;\n width: 400px;\n position: relative;\n}\n\n.truncate-text-multiline:after {\n content: '';\n position: absolute;\n bottom: 0;\n right: 0;\n width: 150px;\n height: 36.4px;\n background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%);\n}",
@ -1324,7 +1275,7 @@
]
},
"meta": {
"hash": "0a38edd4abf4b6229318f70a3d1ae9113c92c557d1b9d2035735ee0a63b97ead",
"hash": "ced5ea18c6b71d918430bd4ca751ff0497c154ab947e2e4b24439744e8671ea6",
"firstSeen": "1547703764",
"lastUpdated": "1588157277",
"updateCount": 12,
@ -1337,8 +1288,7 @@
"type": "snippet",
"attributes": {
"fileName": "truncate-text.md",
"text": "If the text is longer than one line, it will be truncated and end with an ellipsis `…`.\n\n",
"explanation": "\n\n- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).\n- `white-space: nowrap` prevents the text from exceeding one line in height.\n- `text-overflow: ellipsis` makes it so that if the text exceeds its dimensions, it will end with an ellipsis.\n- `width: 200px;` ensures the element has a dimension, to know when to get ellipsis\n- Only works for single line elements.\n",
"text": "If the text is longer than one line, it will be truncated and end with an ellipsis `…`.\n\n- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).\n- `white-space: nowrap` prevents the text from exceeding one line in height.\n- `text-overflow: ellipsis` makes it so that if the text exceeds its dimensions, it will end with an ellipsis.\n- `width: 200px;` ensures the element has a dimension, to know when to get ellipsis\n- Only works for single line elements.\n\n",
"codeBlocks": {
"html": "<p class=\"truncate-text\">If I exceed one line's width, I will be truncated.</p>",
"css": ".truncate-text {\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n width: 200px;\n}",
@ -1351,7 +1301,7 @@
]
},
"meta": {
"hash": "9ce965788761198ab3064b28e2b152621332f9e6a67880744afacb811902d065",
"hash": "2cf2ead8f1385e0c50e6a5f7e0dd46f0a9aa448510a1f9c570a30ff7d8e9a4aa",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 16,
@ -1364,8 +1314,7 @@
"type": "snippet",
"attributes": {
"fileName": "zebra-striped-list.md",
"text": "Creates a striped list with alternating background colors, which is useful for differentiating siblings that have content spread across a wide row.\n\n",
"explanation": "\n\n- Use the `:nth-child(odd)` or `:nth-child(even)` pseudo-class to apply a different background color to elements that match based on their position in a group of siblings.\n- Note that you can use it to apply different styles to other HTML elements like `div`, `tr`, `p`, `ol`, etc.\n",
"text": "Creates a striped list with alternating background colors, which is useful for differentiating siblings that have content spread across a wide row.\n\n- Use the `:nth-child(odd)` or `:nth-child(even)` pseudo-class to apply a different background color to elements that match based on their position in a group of siblings.\n- Note that you can use it to apply different styles to other HTML elements like `div`, `tr`, `p`, `ol`, etc.\n\n",
"codeBlocks": {
"html": "<ul>\n <li>Item 01</li>\n <li>Item 02</li>\n <li>Item 03</li>\n <li>Item 04</li>\n <li>Item 05</li>\n</ul>",
"css": "li:nth-child(odd) {\n background-color: #ddd;\n}",
@ -1378,7 +1327,7 @@
]
},
"meta": {
"hash": "99d2a72988a7c31448540cb548d262c2daf679552aaea27b1ab91d29fc48d2c5",
"hash": "0e7864393bc10ad2a4ab3c049bd086dd2b4876d73a576adea7b0f36eb4c11361",
"firstSeen": "1540966746",
"lastUpdated": "1588157277",
"updateCount": 12,

View File

@ -5,6 +5,12 @@ tags: visual,beginner
Creates a text container with a triangle at the top.
- Use the `:before` and `:after` pseudo-elements to create two triangles.
- The color of the `:before` triangle should be the same as the container's border color.
- The color of the `:after` triangle should be the same as the container's background color.
- The border width of the `:before` triangle should be `1px` wider than the `:after` triangle, in order to act as the border.
- The `:after` triangle should be `1px` to the right of the `:before` triangle to allow for its left border to be shown.
```html
<div class="container">
Border with top triangle
@ -35,11 +41,3 @@ Creates a text container with a triangle at the top.
border-bottom-color: #ffffff;
}
```
#### Explanation
- Use the `:before` and `:after` pseudo-elements to create two triangles.
- The color of the `:before` triangle should be the same as the container's border color.
- The color of the `:after` triangle should be the same as the container's background color.
- The border width of the `:before` triangle should be `1px` wider than the `:after` triangle, in order to act as the border.
- The `:after` triangle should be `1px` to the right of the `:before` triangle to allow for its left border to be shown.

View File

@ -5,6 +5,15 @@ tags: animation,intermediate
Creates a bouncing loader animation.
- `@keyframes` defines an animation that has two states, where the element changes `opacity` and is translated up on the 2D plane using `transform: translate3d()`. Using a single axis translation on `transform: translate3d()` improves the performance of the animation.
- `.bouncing-loader` is the parent container of the bouncing circles and uses `display: flex` and `justify-content: center` to position them in the center.
- `.bouncing-loader > div`, targets the three child `div`s of the parent to be styled. The `div`s are given a width and height of `1rem`, using `border-radius: 50%` to turn them from squares to circles.
- `margin: 3rem 0.2rem` specifies that each circle has a top/bottom margin of `3rem` and left/right margin of `0.2rem` so that they do not directly touch each other, giving them some breathing room.
- `animation` is a shorthand property for the various animation properties: `animation-name`, `animation-duration`, `animation-iteration-count`, `animation-direction` are used.
- `nth-child(n)` targets the element which is the nth child of its parent.
- `animation-delay` is used on the second and third `div` respectively, so that each element does not start the animation at the same time.
- Note that `1rem` is usually `16px`.
```html
<div class="bouncing-loader">
<div></div>
@ -43,15 +52,3 @@ Creates a bouncing loader animation.
animation-delay: 0.4s;
}
```
#### Explanation
Note: `1rem` is usually `16px`.
- `@keyframes` defines an animation that has two states, where the element changes `opacity` and is translated up on the 2D plane using `transform: translate3d()`. Using a single axis translation on `transform: translate3d()` improves the performance of the animation.
- `.bouncing-loader` is the parent container of the bouncing circles and uses `display: flex` and `justify-content: center` to position them in the center.
- `.bouncing-loader > div`, targets the three child `div`s of the parent to be styled. The `div`s are given a width and height of `1rem`, using `border-radius: 50%` to turn them from squares to circles.
- `margin: 3rem 0.2rem` specifies that each circle has a top/bottom margin of `3rem` and left/right margin of `0.2rem` so that they do not directly touch each other, giving them some breathing room.
- `animation` is a shorthand property for the various animation properties: `animation-name`, `animation-duration`, `animation-iteration-count`, `animation-direction` are used.
- `nth-child(n)` targets the element which is the nth child of its parent.
- `animation-delay` is used on the second and third `div` respectively, so that each element does not start the animation at the same time.

View File

@ -5,6 +5,9 @@ tags: layout,beginner
Resets the box-model so that `width` and `height` are not affected by `border` or `padding`.
- `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.
- `box-sizing: inherit` makes an element respect its parent's `box-sizing` rule.
```html
<div class="box">border-box</div>
<div class="box content-box">content-box</div>
@ -36,8 +39,3 @@ div {
box-sizing: content-box;
}
```
#### Explanation
- `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.
- `box-sizing: inherit` makes an element respect its parent's `box-sizing` rule.

View File

@ -5,6 +5,8 @@ tags: animation,intermediate
Creates a border animation on hover.
- Use the `:before` and `:after` pseudo-elements as borders that animate on hover.
```html
<button class="animated-border-button">Submit</button>
```
@ -46,7 +48,3 @@ Creates a border animation on hover.
width: 100%;
}
```
#### Explanation
- Use the `:before` and `:after` pseudo-elements as borders that animate on hover.

View File

@ -5,6 +5,9 @@ tags: visual,beginner
Creates a circle shape with pure CSS.
- `border-radius: 50%` curves the borders of an element to create a circle.
- Since a circle has the same radius at any given point, the `width` and `height` must be the same. Differing values will create an ellipse.
```html
<div class="circle"></div>
```
@ -17,8 +20,3 @@ Creates a circle shape with pure CSS.
background: #333;
}
```
#### Explanation
- `border-radius: 50%` curves the borders of an element to create a circle.
- Since a circle has the same radius at any given point, the `width` and `height` must be the same. Differing values will create an ellipse.

View File

@ -5,6 +5,11 @@ tags: layout,beginner
Ensures that an element self-clears its children.
- `.clearfix:after` defines a pseudo-element.
- `content: ''` allows the pseudo-element to affect layout.
- `clear: both` indicates that the left, right or both sides of the element cannot be adjacent to earlier floated elements within the same block formatting context.
- This is only useful if you are still using `float` to build layouts. Please consider using a modern approach with flexbox layout or grid layout. For this snippet to work properly you need to ensure that there are no non-floating children in the container and that there are no tall floats before the clearfixed container but in the same formatting context (e.g. floated columns).
```html
<div class="clearfix">
<div class="floated">float a</div>
@ -24,10 +29,3 @@ Ensures that an element self-clears its children.
float: left;
}
```
#### Explanation
- `.clearfix:after` defines a pseudo-element.
- `content: ''` allows the pseudo-element to affect layout.
- `clear: both` indicates that the left, right or both sides of the element cannot be adjacent to earlier floated elements within the same block formatting context.
- This is only useful if you are still using `float` to build layouts. Please consider using a modern approach with flexbox layout or grid layout. For this snippet to work properly you need to ensure that there are no non-floating children in the container and that there are no tall floats before the clearfixed container but in the same formatting context (e.g. floated columns).

View File

@ -5,6 +5,9 @@ tags: layout,beginner
Given an element of variable width, it will ensure its `height` remains proportionate in a responsive fashion (i.e. its `width` to `height` ratio remains constant).
- `padding-top` on the `:before` pseudo-element causes the height of the element to equal a percentage of its width. `100%` therefore means the element's height will always be `100%` of the width, creating a responsive square.
- This method also allows content to be placed inside the element normally.
```html
<div class="constant-width-to-height-ratio"></div>
```
@ -27,8 +30,3 @@ Given an element of variable width, it will ensure its `height` remains proporti
clear: both;
}
```
#### Explanation
- `padding-top` on the `:before` pseudo-element causes the height of the element to equal a percentage of its width. `100%` therefore means the element's height will always be `100%` of the width, creating a responsive square.
- This method also allows content to be placed inside the element normally.

View File

@ -5,6 +5,13 @@ tags: visual,advanced
Counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used.
- `counter-reset` is used to initialize a counter, the name of which is the value of the attribute. By default, the counter starts at `0`. This property can also be used to change its value to any specific number.
- `counter-increment` is used for an element that will be countable. Once `counter-reset` is initialized, a counter's value can be increased or decreased.
- `counter(name, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive two parameters, the first being the name of the counter and the second one either `decimal` or `upper-roman` (`decimal` by default).
- `counters(counter, string, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be `decimal` or `upper-roman` (`decimal` by default).
- A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the `counters()` function, separating text can be inserted between different levels of nested counters.
- Note that you can create an ordered list using any type of HTML.
```html
<ul>
<li>List item</li>
@ -30,13 +37,3 @@ li:before {
content: counters(counter, '.') ' ';
}
```
#### Explanation
You can create a ordered list using any type of HTML.
- `counter-reset` is used to initialize a counter, the name of which is the value of the attribute. By default, the counter starts at `0`. This property can also be used to change its value to any specific number.
- `counter-increment` is used for an element that will be countable. Once `counter-reset` is initialized, a counter's value can be increased or decreased.
- `counter(name, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive two parameters, the first being the name of the counter and the second one either `decimal` or `upper-roman` (`decimal` by default).
- `counters(counter, string, style)` displays the value of a section counter. Generally used with the `content` property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be `decimal` or `upper-roman` (`decimal` by default).
- A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the `counters()` function, separating text can be inserted between different levels of nested counters.

View File

@ -5,6 +5,12 @@ tags: visual,advanced
Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.
- `::-webkit-scrollbar` targets the whole scrollbar element.
- `::-webkit-scrollbar-track` targets only the scrollbar track.
- `::-webkit-scrollbar-thumb` targets the scrollbar thumb.
- Apply the same selectors and styles without `.custom-scrollbar` to style the document scrollbar.
- Scrollbar styling doesn't appear to be on any standards track. There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the [WebKit Blog](https://webkit.org/blog/363/styling-scrollbars/).
```html
<div class="custom-scrollbar">
<p>
@ -36,11 +42,3 @@ Customizes the scrollbar style for the document and elements with scrollable ove
border-radius: 12px;
}
```
#### Explanation
- `::-webkit-scrollbar` targets the whole scrollbar element.
- `::-webkit-scrollbar-track` targets only the scrollbar track.
- `::-webkit-scrollbar-thumb` targets the scrollbar thumb.
- Apply the same selectors and styles without `.custom-scrollbar` to style the document scrollbar.
- Scrollbar styling doesn't appear to be on any standards track. There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the [WebKit Blog](https://webkit.org/blog/363/styling-scrollbars/).

View File

@ -5,6 +5,9 @@ tags: visual,beginner
Changes the styling of text selection.
- `::selection` defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.
- Requires prefixes for full support and is not actually in any specification.
```html
<p class="custom-text-selection">Select some of this text.</p>
```
@ -20,8 +23,3 @@ Changes the styling of text selection.
color: white;
}
```
#### Explanation
- `::selection` defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.
- Requires prefixes for full support and is not actually in any specification.

View File

@ -5,6 +5,9 @@ tags: interactivity,beginner
Makes the content unselectable.
- `user-select: none` specifies that the text cannot be selected.
- This is not a secure method to prevent users from copying content.
```html
<p>You can select me.</p>
<p class="unselectable">You can't select me!</p>
@ -15,8 +18,3 @@ Makes the content unselectable.
user-select: none;
}
```
#### Explanation
- `user-select: none` specifies that the text cannot be selected.
- This is not a secure method to prevent users from copying content.

View File

@ -5,6 +5,13 @@ tags: layout,intermediate
Vertically and horizontally centers a child element within its parent element using `display: table` (as an alternative to `flexbox`).
- `display: table` on '.center' allows the element to behave like a `<table>` HTML element.
- 100% height and width on '.center' allows the element to fill the available space within its parent element.
- `display: table-cell` on '.center > span' allows the element to behave like an <td> HTML element.
- `text-align: center` on '.center > span' centers the child element horizontally.
- `vertical-align: middle` on '.center > span' centers the child element vertically.
- The outer parent ('.container' in this case) must have a fixed height and width.
```html
<div class="container">
<div class="center"><span>Centered content</span></div>
@ -30,12 +37,3 @@ Vertically and horizontally centers a child element within its parent element us
vertical-align: middle;
}
```
#### Explanation
- `display: table` on '.center' allows the element to behave like a `<table>` HTML element.
- 100% height and width on '.center' allows the element to fill the available space within its parent element.
- `display: table-cell` on '.center > span' allows the element to behave like an <td> HTML element.
- `text-align: center` on '.center > span' centers the child element horizontally.
- `vertical-align: middle` on '.center > span' centers the child element vertically.
- The outer parent ('.container' in this case) must have a fixed height and width.

View File

@ -5,6 +5,8 @@ tags: animation,intermediate
Creates a donut spinner that can be used to indicate the loading of content.
- Use a semi-transparent `border` for the whole element, except one side that will serve as the loading indicator for the donut. Use `animation` to rotate the element.
```html
<div class="donut"></div>
```
@ -29,7 +31,3 @@ Creates a donut spinner that can be used to indicate the loading of content.
animation: donut-spin 1.2s linear infinite;
}
```
#### Explanation
- Use a semi-transparent `border` for the whole element, except one side that will serve as the loading indicator for the donut. Use `animation` to rotate the element.

View File

@ -5,6 +5,8 @@ tags: visual,beginner
Makes the first letter in the first paragraph bigger than the rest of the text - often used to signify the beginning of a new section.
- Use the `::first-letter` pseudo-element to style the first element of the paragraph, use the `:first-child` selector to select only the first paragraph.
```html
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam commodo ligula quis tincidunt cursus. Integer consectetur tempor ex eget hendrerit. Cras facilisis sodales odio nec maximus. Pellentesque lacinia convallis libero, rhoncus tincidunt ante dictum at. Nullam facilisis lectus tellus, sit amet congue erat sodales commodo.</p>
<p>Donec magna erat, imperdiet non odio sed, sodales tempus magna. Integer vitae orci lectus. Nullam consectetur orci at pellentesque efficitur.</p>
@ -20,7 +22,3 @@ p:first-child::first-letter {
line-height: 1;
}
```
#### Explanation
- Use the `::first-letter` pseudo-element to style the first element of the paragraph, use the `:first-child` selector to select only the first paragraph.

View File

@ -5,6 +5,17 @@ tags: visual,intermediate
Creates a shadow similar to `box-shadow` but based on the colors of the element itself.
- `position: relative` on the element establishes a Cartesian positioning context for psuedo-elements.
- `z-index: 1` establishes a new stacking context.
- `:after` defines a pseudo-element.
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 100%` and `height: 100%` sizes the pseudo-element to fill its parent's dimensions, making it equal in size.
- `background: inherit` causes the pseudo-element to inherit the linear gradient specified on the element.
- `top: 0.5rem` offsets the pseudo-element down slightly from its parent.
- `filter: blur(0.4rem)` will blur the pseudo-element to create the appearance of a shadow underneath.
- `opacity: 0.7` makes the pseudo-element partially transparent.
- `z-index: -1` positions the pseudo-element behind the parent but in front of the background.
```html
<div class="dynamic-shadow"></div>
```
@ -30,16 +41,3 @@ Creates a shadow similar to `box-shadow` but based on the colors of the element
z-index: -1;
}
```
#### Explanation
- `position: relative` on the element establishes a Cartesian positioning context for psuedo-elements.
- `z-index: 1` establishes a new stacking context.
- `:after` defines a pseudo-element.
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 100%` and `height: 100%` sizes the pseudo-element to fill its parent's dimensions, making it equal in size.
- `background: inherit` causes the pseudo-element to inherit the linear gradient specified on the element.
- `top: 0.5rem` offsets the pseudo-element down slightly from its parent.
- `filter: blur(0.4rem)` will blur the pseudo-element to create the appearance of a shadow underneath.
- `opacity: 0.7` makes the pseudo-element partially transparent.
- `z-index: -1` positions the pseudo-element behind the parent but in front of the background.

View File

@ -5,6 +5,9 @@ tags: animation,beginner
Variables that can be reused for `transition-timing-function` properties, more powerful than the built-in `ease`, `ease-in`, `ease-out` and `ease-in-out`.
- The variables are defined globally within the `:root` CSS pseudo-class which matches the root element of a tree representing the document.
- In HTML, `:root` represents the `<html>` element and is identical to the selector `html`, except that its specificity is higher.
```html
<div class="easing-variables">Hover</div>
```
@ -50,8 +53,3 @@ Variables that can be reused for `transition-timing-function` properties, more p
transform: rotate(45deg);
}
```
#### Explanation
- The variables are defined globally within the `:root` CSS pseudo-class which matches the root element of a tree representing the document.
- In HTML, `:root` represents the `<html>` element and is identical to the selector `html`, except that its specificity is higher.

View File

@ -5,6 +5,10 @@ tags: visual,intermediate
Creates an effect where text appears to be "etched" or engraved into the background.
- `text-shadow: 0 2px white` creates a white shadow offset `0px` horizontally and `2px` vertically from the origin position.
- The background must be darker than the shadow for the effect to work.
- The text color should be slightly faded to make it look like it's engraved/carved out of the background.
```html
<p class="etched-text">I appear etched into the background.</p>
```
@ -17,9 +21,3 @@ Creates an effect where text appears to be "etched" or engraved into the backgro
color: #b8bec5;
}
```
#### Explanation
- `text-shadow: 0 2px white` creates a white shadow offset `0px` horizontally and `2px` vertically from the origin position.
- The background must be darker than the shadow for the effect to work.
- The text color should be slightly faded to make it look like it's engraved/carved out of the background.

View File

@ -5,6 +5,10 @@ tags: layout,intermediate
Evenly distributes child elements within a parent element.
- `display: flex` enables flexbox.
- `justify-content: space-between` evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.
- Alternatively, use `justify-content: space-around` to distribute the children with space around them, rather than between them.
```html
<div class="evenly-distributed-children">
<p>Item1</p>
@ -19,10 +23,3 @@ Evenly distributes child elements within a parent element.
justify-content: space-between;
}
```
#### Explanation
- `display: flex` enables flexbox.
- `justify-content: space-between` evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.
- Alternatively, use `justify-content: space-around` to distribute the children with space around them, rather than between them.

View File

@ -5,6 +5,10 @@ tags: layout,visual,intermediate
Changes the fit and position of an image within its container while preserving its aspect ratio. Previously only possible using a background image and the `background-size` property.
- `object-fit: contain` fits the entire image within the container while preserving its aspect ratio.
- `object-fit: cover` fills the container with the image while preserving its aspect ratio.
- `object-position: [x] [y]` positions the image within the container.
```html
<img class="image image-contain" src="https://picsum.photos/600/200" />
<img class="image image-cover" src="https://picsum.photos/600/200" />
@ -28,9 +32,3 @@ Changes the fit and position of an image within its container while preserving i
object-position: right top;
}
```
#### Explanation
- `object-fit: contain` fits the entire image within the container while preserving its aspect ratio.
- `object-fit: cover` fills the container with the image while preserving its aspect ratio.
- `object-position: [x] [y]` positions the image within the container.

View File

@ -5,6 +5,10 @@ tags: layout,beginner
Horizontally and vertically centers a child element within a parent element using `flexbox`.
- `display: flex` creates a flexbox layout.
- `justify-content: center` centers the child horizontally.
- `align-items: center` centers the child vertically.
```html
<div class="flexbox-centering">
<div>Centered content.</div>
@ -19,9 +23,3 @@ Horizontally and vertically centers a child element within a parent element usin
height: 100px;
}
```
#### Explanation
- `display: flex` creates a flexbox layout.
- `justify-content: center` centers the child horizontally.
- `align-items: center` centers the child vertically.

View File

@ -5,6 +5,8 @@ tags: visual,interactivity,intermediate
Changes the appearance of a form if any of its children are focused.
- The psuedo class `:focus-within` applies styles to a parent element if any child element gets focused. For example, an `input` element inside a `form` element.
```html
<form>
<label for="username">Username:</label>
@ -35,7 +37,3 @@ input {
margin: 4px;
}
```
#### Explanation
- The psuedo class `:focus-within` applies styles to a parent element if any child element gets focused. For example, an `input` element inside a `form` element.

View File

@ -5,6 +5,8 @@ tags: visual,advanced
The `:fullscreen` CSS pseudo-element represents an element that's displayed when the browser is in fullscreen mode.
- `:fullscreen` CSS pseudo-element selector is used to select and style an element that is being displayed in fullscreen mode.
```html
<div class="container">
<p><em>Click the button below to enter the element into fullscreen mode. </em></p>
@ -46,7 +48,3 @@ The `:fullscreen` CSS pseudo-element represents an element that's displayed when
height: 100vh;
}
```
#### Explanation
- `:fullscreen` CSS pseudo-element selector is used to select and style an element that is being displayed in fullscreen mode.

View File

@ -5,6 +5,11 @@ tags: visual,intermediate
Gives text a gradient color.
- `background: -webkit-linear-gradient(...)` gives the text element a gradient background.
- `webkit-text-fill-color: transparent` fills the text with a transparent color.
- `webkit-background-clip: text` clips the background with the text, filling the text with the gradient background as the color.
- Uses non-standard properties.
```html
<p class="gradient-text">Gradient text</p>
```
@ -17,10 +22,3 @@ Gives text a gradient color.
font-size: 32px;
}
```
#### Explanation
- `background: -webkit-linear-gradient(...)` gives the text element a gradient background.
- `webkit-text-fill-color: transparent` fills the text with a transparent color.
- `webkit-background-clip: text` clips the background with the text, filling the text with the gradient background as the color.
- Uses non-standard properties.

View File

@ -5,6 +5,10 @@ tags: layout,beginner
Horizontally and vertically centers a child element within a parent element using `grid`.
- `display: grid` creates a grid layout
- `justify-content: center` centers the child horizontally.
- `align-items: center` centers the child vertically.
```html
<div class="grid-centering">
<div class="child">Centered content.</div>
@ -19,9 +23,3 @@ Horizontally and vertically centers a child element within a parent element usin
height: 100px;
}
```
#### Explanation
- `display: grid` creates a grid layout
- `justify-content: center` centers the child horizontally.
- `align-items: center` centers the child vertically.

View File

@ -5,6 +5,13 @@ tags: interactivity,beginner
Displays a hamburger menu which transitions to a cross on hover.
- Use a `.hamburger-menu` container `div` which contains the top, bottom, and middle bars.
- The container is set to be a flex container (`display: flex`) with `flex-direction` to be `column` and `flex-wrap` to be `wrap` (alternatively, you can set both properties by a shorthand `flex-flow: column wrap`).
- Add distance between the bars using `justify-content: space-between`.
- The animation has 3 parts: top and bottom bars transforming to 45 degree angles (`rotate(45deg)`), and the middle bar fading away by setting `opacity: 0`.
- The `transform-origin` is set to `left` so the bars rotate around the left point.
- Set `transition all 0.5s` so that both `transform` and `opacity` properties are animated for half a second.
```html
<div class="hamburger-menu">
<div class="bar top"></div>
@ -45,12 +52,3 @@ Displays a hamburger menu which transitions to a cross on hover.
transform: rotate(-45deg);
}
```
#### Explanation
- Use a `.hamburger-menu` container `div` which contains the top, bottom, and middle bars.
- The container is set to be a flex container (`display: flex`) with `flex-direction` to be `column` and `flex-wrap` to be `wrap` (alternatively, you can set both properties by a shorthand `flex-flow: column wrap`).
- Add distance between the bars using `justify-content: space-between`.
- The animation has 3 parts: top and bottom bars transforming to 45 degree angles (`rotate(45deg)`), and the middle bar fading away by setting `opacity: 0`.
- The `transform-origin` is set to `left` so the bars rotate around the left point.
- Set `transition all 0.5s` so that both `transform` and `opacity` properties are animated for half a second.

View File

@ -5,6 +5,14 @@ tags: animation,intermediate
Transitions an element's height from `0` to `auto` when its height is unknown.
- `transition: max-height: 0.5s cubic-bezier(...)` specifies that changes to `max-height` should be transitioned over 0.5 seconds, using an `ease-out-quint` timing function.
- `overflow: hidden` prevents the contents of the hidden element from overflowing its container.
- `max-height: 0` specifies that the element has no height initially.
- `.target:hover > .el` specifies that when the parent is hovered over, target a child `.el` within it and use the `--max-height` variable which was defined by JavaScript.
- `el.scrollHeight` is the height of the element including overflow, which will change dynamically based on the content of the element.
- `el.style.setProperty(...)` sets the `--max-height` CSS variable which is used to specify the `max-height` of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.
- Causes reflow on each animation frame, which will be laggy if there are a large number of elements beneath the element that is transitioning in height.
```html
<div class="trigger">
Hover me to see a height transition.
@ -29,13 +37,3 @@ let el = document.querySelector('.el');
let height = el.scrollHeight;
el.style.setProperty('--max-height', height + 'px');
```
#### Explanation
- `transition: max-height: 0.5s cubic-bezier(...)` specifies that changes to `max-height` should be transitioned over 0.5 seconds, using an `ease-out-quint` timing function.
- `overflow: hidden` prevents the contents of the hidden element from overflowing its container.
- `max-height: 0` specifies that the element has no height initially.
- `.target:hover > .el` specifies that when the parent is hovered over, target a child `.el` within it and use the `--max-height` variable which was defined by JavaScript.
- `el.scrollHeight` is the height of the element including overflow, which will change dynamically based on the content of the element.
- `el.style.setProperty(...)` sets the `--max-height` CSS variable which is used to specify the `max-height` of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.
- Causes reflow on each animation frame, which will be laggy if there are a large number of elements beneath the element that is transitioning in height.

View File

@ -5,6 +5,14 @@ tags: animation,intermediate
Creates a shadow box around the text when it is hovered.
- `display: inline-block` to set width and length for `p` element thus making it an `inline-block`.
- Set `transform: perspective(1px)` to give element a 3D space by affecting the distance between the Z plane and the user and `translate(0)` to reposition the `p` element along z-axis in 3D space.
- `box-shadow:` to set up the box.
- `transparent` to make box transparent.
- `transition-property` to enable transitions for both `box-shadow` and `transform`.
- `:hover` to activate whole css when hovering is done until `active`.
- `transform: scale(1.2)` to change the scale, magnifying the text.
```html
<p class="hover-shadow-box-animation">Box it!</p>
```
@ -27,13 +35,3 @@ Creates a shadow box around the text when it is hovered.
transform: scale(1.2);
}
```
#### Explanation
- `display: inline-block` to set width and length for `p` element thus making it an `inline-block`.
- Set `transform: perspective(1px)` to give element a 3D space by affecting the distance between the Z plane and the user and `translate(0)` to reposition the `p` element along z-axis in 3D space.
- `box-shadow:` to set up the box.
- `transparent` to make box transparent.
- `transition-property` to enable transitions for both `box-shadow` and `transform`.
- `:hover` to activate whole css when hovering is done until `active`.
- `transform: scale(1.2)` to change the scale, magnifying the text.

View File

@ -5,6 +5,17 @@ tags: animation,advanced
Creates an animated underline effect when the text is hovered over.
- `display: inline-block` makes the block `p` an `inline-block` to prevent the underline from spanning the entire parent width rather than just the content (text).
- `position: relative` on the element establishes a Cartesian positioning context for pseudo-elements.
- `:after` defines a pseudo-element.
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 100%` ensures the pseudo-element spans the entire width of the text block.
- `transform: scaleX(0)` initially scales the pseudo element to 0 so it has no width and is not visible.
- `bottom: 0` and `left: 0` position it to the bottom left of the block.
- `transition: transform 0.25s ease-out` means changes to `transform` will be transitioned over 0.25 seconds with an `ease-out` timing function.
- `transform-origin: bottom right` means the transform anchor point is positioned at the bottom right of the block.
- `:hover:after` then uses `scaleX(1)` to transition the width to 100%, then changes the `transform-origin` to `bottom left` so that the anchor point is reversed, allowing it transition out in the other direction when hovered off.
```html
<p class="hover-underline-animation">Hover this text to see the effect!</p>
```
@ -34,16 +45,3 @@ Creates an animated underline effect when the text is hovered over.
transform-origin: bottom left;
}
```
#### Explanation
- `display: inline-block` makes the block `p` an `inline-block` to prevent the underline from spanning the entire parent width rather than just the content (text).
- `position: relative` on the element establishes a Cartesian positioning context for pseudo-elements.
- `:after` defines a pseudo-element.
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 100%` ensures the pseudo-element spans the entire width of the text block.
- `transform: scaleX(0)` initially scales the pseudo element to 0 so it has no width and is not visible.
- `bottom: 0` and `left: 0` position it to the bottom left of the block.
- `transition: transform 0.25s ease-out` means changes to `transform` will be transitioned over 0.25 seconds with an `ease-out` timing function.
- `transform-origin: bottom right` means the transform anchor point is positioned at the bottom right of the block.
- `:hover:after` then uses `scaleX(1)` to transition the width to 100%, then changes the `transform-origin` to `bottom left` so that the anchor point is reversed, allowing it transition out in the other direction when hovered off.

View File

@ -5,6 +5,11 @@ tags: layout,animation,intermediate
Displays a menu overlay when the image is hovered.
- Use a `figure` to wrap the `img` element and a `div` element that will contain the menu links.
- Use the `opacity` and `right` attributes to animate the image on hover, to create a sliding effect.
- Set the `left` attribute of the `div` to the negative of the element's `width` and reset it to `0` when hovering over the parent element to slide in the menu.
- Use `display: flex`, `flex-direction: column` and `justify-content: center` on the `div` to vertically center the menu items.
```html
<figure class="hover-menu">
<img src="https://i.picsum.photos/id/1060/800/480.jpg"/>
@ -82,10 +87,3 @@ Displays a menu overlay when the image is hovered.
opacity: 1;
}
```
#### Explanation
- Use a `figure` to wrap the `img` element and a `div` element that will contain the menu links.
- Use the `opacity` and `right` attributes to animate the image on hover, to create a sliding effect.
- Set the `left` attribute of the `div` to the negative of the element's `width` and reset it to `0` when hovering over the parent element to slide in the menu.
- Use `display: flex`, `flex-direction: column` and `justify-content: center` on the `div` to vertically center the menu items.

View File

@ -5,6 +5,9 @@ tags: animation,visual,intermediate
Creates a rotate effect for the image on hover.
- Use `scale` and `rotate` when hovering over the parent element (a `figure`) to animate the image, using the `transition` property.
- Use `overflow: hidden` on the parent container to hide the excess from the image transformation.
```html
<figure class="hover-rotate">
<img src="https://i.picsum.photos/id/669/600/800.jpg"/>
@ -30,8 +33,3 @@ Creates a rotate effect for the image on hover.
transform: scale(1.3) rotate(5deg);
}
```
#### Explanation
- Use `scale` and `rotate` when hovering over the parent element (a `figure`) to animate the image, using the `transition` property.
- Use `overflow: hidden` on the parent container to hide the excess from the image transformation.

View File

@ -5,6 +5,10 @@ tags: visual,animation,advanced
Displays an image overlay effect on hover.
- Use the `:before` and `:after` elements for the top and bottom bars of the overlay respectively, setting their `opacity`, `transform` and `transition` to produce the desired effect.
- Use the `figcaption` for the text of the overlay, setting `display: flex`, `flex-direction: column` and `justify-content: center` to center the text into the image.
- Use the `:hover` pseudo-selector to update the `opacity` and `transform` of all the elements and produce the desired effect.
```html
<figure class="hover-img">
<img src="https://i.picsum.photos/id/200/440/320.jpg"/>
@ -92,9 +96,3 @@ Displays an image overlay effect on hover.
opacity: 1;
}
```
#### Explanation
- Use the `:before` and `:after` elements for the top and bottom bars of the overlay respectively, setting their `opacity`, `transform` and `transition` to produce the desired effect.
- Use the `figcaption` for the text of the overlay, setting `display: flex`, `flex-direction: column` and `justify-content: center` to center the text into the image.
- Use the `:hover` pseudo-selector to update the `opacity` and `transform` of all the elements and produce the desired effect.

View File

@ -5,6 +5,11 @@ tags: layout,advanced
Creates a vertical masonry layout using HTML and CSS.
- Create a masonry-style layout that consists of "bricks" that fall into each other with either a fixed `width` (vertical layout) or a fixed `height` (horizontal layout), forming a perfect fit. Especially useful when working with images.
- `.masonry-container` is the container for the masonry layout. Within that container, there's a `div.masonry-columns`, which will automatically put each child element, `.masonry-brick`, into the layout.
- `.masonry-brick` must be have `display: block` to allow the layout to flow properly, while the `:first-child` of this class should have a different `margin` to account for its positioning.
- CSS variables are used to allow for greater flexibility for the layout, while media queries ensure that the layout flows responsively in different viewport sizes.
```html
<div class="masonry-container">
<div class="masonry-columns">
@ -61,10 +66,3 @@ Creates a vertical masonry layout using HTML and CSS.
margin: 0 0 var(--column-gap);
}
```
#### Explanation
- Create a masonry-style layout that consists of "bricks" that fall into each other with either a fixed `width` (vertical layout) or a fixed `height` (horizontal layout), forming a perfect fit. Especially useful when working with images.
- `.masonry-container` is the container for the masonry layout. Within that container, there's a `div.masonry-columns`, which will automatically put each child element, `.masonry-brick`, into the layout.
- `.masonry-brick` must be have `display: block` to allow the layout to flow properly, while the `:first-child` of this class should have a different `margin` to account for its positioning.
- CSS variables are used to allow for greater flexibility for the layout, while media queries ensure that the layout flows responsively in different viewport sizes.

View File

@ -5,6 +5,10 @@ tags: visual,interactivity,advanced
A hover effect where the gradient follows the mouse cursor.
- `--x` and `--y` are used to track the position of the mouse on the button.
- `--size` is used to keep modify of the gradient's dimensions.
- `background: radial-gradient(circle closest-side, pink, transparent);` creates the gradient at the correct postion.
```html
<button class="mouse-cursor-gradient-tracking">
<span>Hover me</span>
@ -56,9 +60,3 @@ btn.onmousemove = function(e) {
btn.style.setProperty('--y', y + 'px');
}
```
#### Explanation
- `--x` and `--y` are used to track the position of the mouse on the button.
- `--size` is used to keep modify of the gradient's dimensions.
- `background: radial-gradient(circle closest-side, pink, transparent);` creates the gradient at the correct postion.

View File

@ -5,6 +5,10 @@ tags: visual,beginner
Fancy hover and focus effect at navigation items using transform CSS property.
- Use the `:before` pseudo-element at the list item anchor to create a hover effect, hide it using `transform: scale(0)`.
- Use the `:hover` and `:focus` pseudo-selectors to transition to `transform: scale(1)` and show the pseudo-element with its colored background.
- Prevent the pseudo-element from covering the anchor element by using `z-index: -1`.
```html
<nav class="hover-nav">
<ul>
@ -54,9 +58,3 @@ li a:focus:before {
transform: scale(1);
}
```
#### Explanation
- Use the `:before` pseudo-element at the list item anchor to create a hover effect, hide it using `transform: scale(0)`.
- Use the `:hover` and `:focus` pseudo-selectors to transition to `transform: scale(1)` and show the pseudo-element with its colored background.
- Prevent the pseudo-element from covering the anchor element by using `z-index: -1`.

View File

@ -6,6 +6,14 @@ tags: layout,visual,intermediate
Completely hides an element visually and positionally in the DOM while still allowing it to be accessible.
Provides an alternative to `display: none` (not readable by screen readers) and `visibility: hidden` (takes up physical space in the DOM).
- Remove all borders.
- Use `clip` to indicate that no part of the element should be shown.
- Make the height and width of the element 1px.
- Negate the elements height and width using `margin: -1px`.
- Hide the element's overflow.
- Remove all padding.
- Position the element absolutely so that it does not take up space in the DOM.
```html
<a class="button" href="https://google.com">
Learn More <span class="offscreen"> about pants</span>
@ -24,13 +32,3 @@ Provides an alternative to `display: none` (not readable by screen readers) and
width: 1px;
}
```
#### Explanation
- Remove all borders.
- Use `clip` to indicate that no part of the element should be shown.
- Make the height and width of the element 1px.
- Negate the elements height and width using `margin: -1px`.
- Hide the element's overflow.
- Remove all padding.
- Position the element absolutely so that it does not take up space in the DOM.

View File

@ -5,6 +5,15 @@ tags: visual,intermediate
Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled.
- `position: relative` on the parent establishes a Cartesian positioning context for pseudo-elements.
- `:after` defines a pseudo element.
- `background-image: linear-gradient(...)` adds a linear gradient that fades from transparent to white (top to bottom).
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 240px` matches the size of the scrolling element (which is a child of the parent that has the pseudo element).
- `height: 25px` is the height of the fading gradient pseudo-element, which should be kept relatively small.
- `bottom: 0` positions the pseudo-element at the bottom of the parent.
- `pointer-events: none` specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.
```html
<div class="overflow-scroll-gradient">
<div class="overflow-scroll-gradient-scroller">
@ -44,14 +53,3 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
line-height: 1.2;
}
```
#### Explanation
- `position: relative` on the parent establishes a Cartesian positioning context for pseudo-elements.
- `:after` defines a pseudo element.
- `background-image: linear-gradient(...)` adds a linear gradient that fades from transparent to white (top to bottom).
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 240px` matches the size of the scrolling element (which is a child of the parent that has the pseudo element).
- `height: 25px` is the height of the fading gradient pseudo-element, which should be kept relatively small.
- `bottom: 0` positions the pseudo-element at the bottom of the parent.
- `pointer-events: none` specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.

View File

@ -5,6 +5,14 @@ tags: interactivity,intermediate
Reveals an interactive popout menu on hover and focus.
- `position: relative` on the reference parent establishes a Cartesian positioning context for its child.
- `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.
- `left: 100%` moves the the popout menu 100% of its parent's width from the left.
- `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).
- `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.
- `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.
- `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is within the reference.
```html
<div class="reference" tabindex="0">
<div class="popout-menu">Popout menu</div>
@ -34,13 +42,3 @@ Reveals an interactive popout menu on hover and focus.
visibility: visible;
}
```
#### Explanation
- `position: relative` on the reference parent establishes a Cartesian positioning context for its child.
- `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.
- `left: 100%` moves the the popout menu 100% of its parent's width from the left.
- `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).
- `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.
- `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.
- `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is _within_ the reference.

View File

@ -6,6 +6,11 @@ tags: visual,intermediate
A nicer alternative to `text-decoration: underline` where descenders do not clip the underline.
Natively implemented as `text-decoration-skip-ink: auto` but it has less control over the underline.
- `text-shadow` uses 4 values with offsets that cover a 4x4 px area to ensure the underline has a "thick" shadow that covers the line where descenders clip it. Use a color that matches the background. For a larger font, use a larger `px` size. Additional values can create an even thicker shadow, and subpixel values can also be used.
- `background-image: linear-gradient(...)` creates a 90deg gradient using the text color (`currentColor`).
- The `background-*` properties size the gradient as 100% of the width of the block and 1px in height at the bottom and disables repetition, which creates a 1px underline beneath the text.
- The `::selection` pseudo selector rule ensures the text shadow does not interfere with text selection.
```html
<p class="pretty-text-underline">Pretty text underline without clipping descenders.</p>
```
@ -30,10 +35,3 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
text-shadow: none;
}
```
#### Explanation
- `text-shadow` uses 4 values with offsets that cover a 4x4 px area to ensure the underline has a "thick" shadow that covers the line where descenders clip it. Use a color that matches the background. For a larger font, use a larger `px` size. Additional values can create an even thicker shadow, and subpixel values can also be used.
- `background-image: linear-gradient(...)` creates a 90deg gradient using the text color (`currentColor`).
- The `background-*` properties size the gradient as 100% of the width of the block and 1px in height at the bottom and disables repetition, which creates a 1px underline beneath the text.
- The `::selection` pseudo selector rule ensures the text shadow does not interfere with text selection.

View File

@ -5,6 +5,11 @@ tags: animation,beginner
Creates a pulse effect loader animation using the `animation-delay` property.
- Use `@keyframes` to define an animation at two points in the cycle, start (`0%`), where the two `<div>` elements have no `width` or `height` and are positioned at the center and end (`100%`), where both `<div>` elements have increased `width` and `height`, but their `position` is reset to `0`.
- Use `opacity` to transition from `1` to `0` when animating to give the `<div>` elements a disappearing effect as they expand.
- `.ripple-loader`, which is the parent container, has a predefined `width` and `height`. It uses `position: relative` to position its children.
- Use `animation-delay` on the second `<div>` element, so that each element starts its animation at a different time.
```html
<div class="ripple-loader">
<div></div>
@ -47,10 +52,3 @@ Creates a pulse effect loader animation using the `animation-delay` property.
}
}
```
#### Explanation
- Use `@keyframes` to define an animation at two points in the cycle, start (`0%`), where the two `<div>` elements have no `width` or `height` and are positioned at the center and end (`100%`), where both `<div>` elements have increased `width` and `height`, but their `position` is reset to `0`.
- Use `opacity` to transition from `1` to `0` when animating to give the `<div>` elements a disappearing effect as they expand.
- `.ripple-loader`, which is the parent container, has a predefined `width` and `height`. It uses `position: relative` to position its children.
- Use `animation-delay` on the second `<div>` element, so that each element starts its animation at a different time.

View File

@ -5,6 +5,8 @@ tags: visual,beginner
Resets all styles to default values with one property. This will not affect `direction` and `unicode-bidi` properties.
- The `all` property allows you to reset all styles (inherited or not) to default values.
```html
<div class="reset-all-styles">
<h5>Title</h5>
@ -21,7 +23,3 @@ Resets all styles to default values with one property. This will not affect `dir
all: initial;
}
```
#### Explanation
- The `all` property allows you to reset all styles (inherited or not) to default values.

View File

@ -5,6 +5,14 @@ tags: visual,intermediate
Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.
- `position: relative` on the element establishes a Cartesian positioning context for pseudo elements.
- `:after` defines a pseudo element.
- `background-image: url(...)` adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use [the URL-encoder for SVG](http://yoksel.github.io/url-encoder/).
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 100%` ensures the element stretches the entire width of its parent.
- `height: 12px` is the same height as the shape.
- `bottom: 0` positions the pseudo element at the bottom of the parent.
```html
<div class="shape-separator"></div>
```
@ -25,13 +33,3 @@ Uses an SVG shape to separate two different blocks to create more a interesting
bottom: 0;
}
```
#### Explanation
- `position: relative` on the element establishes a Cartesian positioning context for pseudo elements.
- `:after` defines a pseudo element.
- `background-image: url(...)` adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use [the URL-encoder for SVG](http://yoksel.github.io/url-encoder/).
- `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
- `width: 100%` ensures the element stretches the entire width of its parent.
- `height: 12px` is the same height as the shape.
- `bottom: 0` positions the pseudo element at the bottom of the parent.

View File

@ -5,6 +5,9 @@ tags: interactivity,intermediate
Fades out the siblings of a hovered item.
- `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.3 seconds.
- `.sibling-fade:hover span:not(:hover)` specifies that when the parent is hovered, select any `span` children that are not currently being hovered and change their opacity to `0.5`.
```html
<div class="sibling-fade">
<span>Item 1</span> <span>Item 2</span> <span>Item 3</span> <span>Item 4</span>
@ -22,8 +25,3 @@ span {
opacity: 0.5;
}
```
#### Explanation
- `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.3 seconds.
- `.sibling-fade:hover span:not(:hover)` specifies that when the parent is hovered, select any `span` children that are not currently being hovered and change their opacity to `0.5`.

View File

@ -5,6 +5,11 @@ tags: animation,advanced
Creates a staggered animation for the elements of a list.
- Set the `opacity` to `0` and `transform` to `translateX(100%)` to make list elements transparent and move them all the way to the right.
- Specify the appropriate `transition` properties for list elements, except `transition-delay` which is specified relative to the `--i` custom property.
- Use inline styles to specify a value for `--i` for each list element, which will in turn be used for `transition-delay` to create the stagger effect.
- Use the `:checked` selector for the checkbox to appropriately style list elements, setting `opacity` to `1` and `transform` to `translateX(0)` to make them appear and slide into view.
```html
<div class="container">
<input type="checkbox" name="menu" id="menu" class="menu-toggler">
@ -57,10 +62,3 @@ Creates a staggered animation for the elements of a list.
transition-delay: calc(0.055s * var(--i));
}
```
#### Explanation
- Set the `opacity` to `0` and `transform` to `translateX(100%)` to make list elements transparent and move them all the way to the right.
- Specify the appropriate `transition` properties for list elements, except `transition-delay` which is specified relative to the `--i` custom property.
- Use inline styles to specify a value for `--i` for each list element, which will in turn be used for `transition-delay` to create the stagger effect.
- Use the `:checked` selector for the checkbox to appropriately style list elements, setting `opacity` to `1` and `transform` to `translateX(0)` to make them appear and slide into view.

View File

@ -5,6 +5,18 @@ tags: visual,beginner
Uses the native font of the operating system to get close to a native app feel.
- The browser looks for each successive font, preferring the first one if possible, and falls back to the next if it cannot find the font (on the system or defined in CSS).
- `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however).
- `BlinkMacSystemFont` is San Francisco, used on macOS Chrome.
- `Segoe UI` is used on Windows 10.
- `Roboto` is used on Android.
- `Oxygen-Sans` is used on Linux with KDE.
- `Ubuntu` is used on Ubuntu (all variants).
- `Cantarell` is used on Linux with GNOME Shell.
- `"Helvetica Neue"` and `Helvetica` is used on macOS 10.10 and below (wrapped in quotes because it has a space).
- `Arial` is a font widely supported by all operating systems.
- `sans-serif` is the fallback sans-serif font if none of the other fonts are supported.
```html
<p class="system-font-stack">This text uses the system font.</p>
```
@ -15,18 +27,3 @@ Uses the native font of the operating system to get close to a native app feel.
Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
```
#### Explanation
The browser looks for each successive font, preferring the first one if possible, and falls back to the next if it cannot find the font (on the system or defined in CSS).
- `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however)
- `BlinkMacSystemFont` is San Francisco, used on macOS Chrome
- `Segoe UI` is used on Windows 10
- `Roboto` is used on Android
- `Oxygen-Sans` is used on Linux with KDE
- `Ubuntu` is used on Ubuntu (all variants)
- `Cantarell` is used on Linux with GNOME Shell
- `"Helvetica Neue"` and `Helvetica` is used on macOS 10.10 and below (wrapped in quotes because it has a space)
- `Arial` is a font widely supported by all operating systems
- `sans-serif` is the fallback sans-serif font if none of the other fonts are supported

View File

@ -5,6 +5,12 @@ tags: layout,beginner
Align items horizontally using `display: inline-block` to create a 3-tile layout.
- Use `display: inline-block` to create a tiled layout, without using `float`, `flex` or `grid`.
- `.tiles` is the container component, `.tile` is an item that needs to be displayed inline.
- Use `width: calc((900px / 3))` to divide the width of the container evenly into 3 columns.
- Set `font-size: 0;` on `.tiles` to avoid whitespace.
- Set `font-size: 20px` to `h2` in order to display the text.
```html
<div class="tiles">
<div class="tile">
@ -38,11 +44,3 @@ Align items horizontally using `display: inline-block` to create a 3-tile layout
font-size: 20px;
}
```
#### Explanation
- Use `display: inline-block` to create a tiled layout, without using `float`, `flex` or `grid`.
- `.tiles` is the container component, `.tile` is an item that needs to be displayed inline.
- Use `width: calc((900px / 3))` to divide the width of the container evenly into 3 columns.
- Set `font-size: 0;` on `.tiles` to avoid whitespace.
- Set `font-size: 20px` to `h2` in order to display the text.

View File

@ -5,6 +5,15 @@ tags: visual,interactivity,beginner
Creates a toggle switch with CSS only.
- This effect is styling only the `<label>` element to look like a toggle switch, and hiding the actual `<input>` checkbox by positioning it offscreen. When clicking the label associated with the `<input>` element, it sets the `<input>` checkbox into the `:checked` state.
- The `for` attribute associates the `<label>` with the appropriate `<input>` checkbox element by its `id`.
- `.switch:after` defines a pseudo-element for the `<label>` to create the circular knob.
- `input[type='checkbox']:checked + .switch:after` targets the `<label>`'s pseudo-element's style when the checkbox is `checked`.
- `transform: translateX(20px)` moves the pseudo-element (knob) 20px to the right when the checkbox is `checked`.
- `background-color: #7983ff;` sets the background-color of the switch to a different color when the checkbox is `checked`.
- `.offscreen` moves the `<input>` checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it is accessible via keyboard and screen readers.
- `transition: all 0.3s` specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the `<label>`'s `background-color` and the pseudo-element's `transform` property when the checkbox is checked.
```html
<input type="checkbox" id="toggle" class="offscreen" /> <label for="toggle" class="switch"></label>
```
@ -45,15 +54,3 @@ input[type='checkbox']:checked + .switch {
left: -9999px;
}
```
#### Explanation
This effect is styling only the `<label>` element to look like a toggle switch, and hiding the actual `<input>` checkbox by positioning it offscreen. When clicking the label associated with the `<input>` element, it sets the `<input>` checkbox into the `:checked` state.
- The `for` attribute associates the `<label>` with the appropriate `<input>` checkbox element by its `id`.
- `.switch:after` defines a pseudo-element for the `<label>` to create the circular knob.
- `input[type='checkbox']:checked + .switch:after` targets the `<label>`'s pseudo-element's style when the checkbox is `checked`.
- `transform: translateX(20px)` moves the pseudo-element (knob) 20px to the right when the checkbox is `checked`.
- `background-color: #7983ff;` sets the background-color of the switch to a different color when the checkbox is `checked`.
- `.offscreen` moves the `<input>` checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it is accessible via keyboard and screen readers.
- `transition: all 0.3s` specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the `<label>`'s `background-color` and the pseudo-element's `transform` property when the checkbox is checked.

View File

@ -3,7 +3,13 @@ title: Transform centering
tags: layout,beginner
---
Vertically and horizontally centers a child element within its parent element using `position: absolute` and `transform: translate()` (as an alternative to `flexbox` or `display: table`). Similar to `flexbox`, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.
Vertically and horizontally centers a child element within its parent element using `position: absolute` and `transform: translate()` (as an alternative to `flexbox` or `display: table`).
Similar to `flexbox`, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.
- `position: absolute` on the child element allows it to be positioned based on its containing block.
- `left: 50%` and `top: 50%` offsets the child 50% from the left and top edge of its containing block.
- `transform: translate(-50%, -50%)` allows the height and width of the child element to be negated so that it is vertically and horizontally centered.
- Note that the fixed height and width on parent element is for the demo only.
```html
<div class="parent">
@ -27,10 +33,3 @@ Vertically and horizontally centers a child element within its parent element us
text-align: center;
}
```
#### Explanation
- `position: absolute` on the child element allows it to be positioned based on its containing block.
- `left: 50%` and `top: 50%` offsets the child 50% from the left and top edge of its containing block.
- `transform: translate(-50%, -50%)` allows the height and width of the child element to be negated so that it is vertically and horizontally centered.
- Note that the fixed height and width on parent element is for the demo only.

View File

@ -5,6 +5,9 @@ tags: visual,beginner
Creates a triangle shape with pure CSS.
- The color of the border is the color of the triangle. The side the triangle tip points corresponds to the opposite `border-*` property. For example, a color on `border-top` means the arrow points downward.
- Experiment with the `px` values to change the proportion of the triangle.
```html
<div class="triangle"></div>
```
@ -18,8 +21,3 @@ Creates a triangle shape with pure CSS.
border-right: 20px solid transparent;
}
```
#### Explanation
- The color of the border is the color of the triangle. The side the triangle tip points corresponds to the opposite `border-*` property. For example, a color on `border-top` means the arrow points downward.
- Experiment with the `px` values to change the proportion of the triangle.

View File

@ -5,6 +5,12 @@ tags: layout,intermediate
If the text is longer than one line, it will be truncated for `n` lines and end with an gradient fade.
- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).
- `width: 400px` ensures the element has a dimension.
- `height: 109.2px` calculated value for height, it equals `font-size * line-height * numberOfLines` (in this case `26 * 1.4 * 3 = 109.2`).
- `height: 36.4px` calculated value for gradient container, it equals `font-size * line-height` (in this case `26 * 1.4 = 36.4`).
- `background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%)` gradient from `transparent` to `#f5f6f9`.
```html
<p class="truncate-text-multiline">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
@ -34,11 +40,3 @@ If the text is longer than one line, it will be truncated for `n` lines and end
background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%);
}
```
#### Explanation
- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).
- `width: 400px` ensures the element has a dimension.
- `height: 109.2px` calculated value for height, it equals `font-size * line-height * numberOfLines` (in this case `26 * 1.4 * 3 = 109.2`)
- `height: 36.4px` calculated value for gradient container, it equals `font-size * line-height` (in this case `26 * 1.4 = 36.4`)
- `background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%)` gradient from `transparent` to `#f5f6f9`

View File

@ -5,6 +5,12 @@ tags: layout,beginner
If the text is longer than one line, it will be truncated and end with an ellipsis `…`.
- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).
- `white-space: nowrap` prevents the text from exceeding one line in height.
- `text-overflow: ellipsis` makes it so that if the text exceeds its dimensions, it will end with an ellipsis.
- `width: 200px;` ensures the element has a dimension, to know when to get ellipsis
- Only works for single line elements.
```html
<p class="truncate-text">If I exceed one line's width, I will be truncated.</p>
```
@ -17,11 +23,3 @@ If the text is longer than one line, it will be truncated and end with an ellips
width: 200px;
}
```
#### Explanation
- `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).
- `white-space: nowrap` prevents the text from exceeding one line in height.
- `text-overflow: ellipsis` makes it so that if the text exceeds its dimensions, it will end with an ellipsis.
- `width: 200px;` ensures the element has a dimension, to know when to get ellipsis
- Only works for single line elements.

View File

@ -5,6 +5,9 @@ tags: visual,beginner
Creates a striped list with alternating background colors, which is useful for differentiating siblings that have content spread across a wide row.
- Use the `:nth-child(odd)` or `:nth-child(even)` pseudo-class to apply a different background color to elements that match based on their position in a group of siblings.
- Note that you can use it to apply different styles to other HTML elements like `div`, `tr`, `p`, `ol`, etc.
```html
<ul>
<li>Item 01</li>
@ -20,8 +23,3 @@ li:nth-child(odd) {
background-color: #ddd;
}
```
#### Explanation
- Use the `:nth-child(odd)` or `:nth-child(even)` pseudo-class to apply a different background color to elements that match based on their position in a group of siblings.
- Note that you can use it to apply different styles to other HTML elements like `div`, `tr`, `p`, `ol`, etc.