{ "data": [ { "id": "border-with-top-triangle", "title": "Border with top triangle", "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", "codeBlocks": { "html": "
Select some of this text.
", "css": "::selection {\n background: aquamarine;\n color: black;\n}\n\n.custom-text-selection::selection {\n background: deeppink;\n color: white;\n}", "js": "", "scopedCss": "[data-scope=\"custom-text-selection\"] ::selection {\n background: aquamarine;\n color: black; }\n\n[data-scope=\"custom-text-selection\"] .custom-text-selection::selection {\n background: deeppink;\n color: white; }\n" }, "tags": [ "visual", "beginner" ] }, "meta": { "hash": "881222d40e158eba5312b94563a47ed3840a475ceab10a54265f8a0d263e9cd9", "firstSeen": "1519564479", "lastUpdated": "1588157277", "updateCount": 17, "authorCount": 6 } }, { "id": "disable-selection", "title": "Disable selection", "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", "codeBlocks": { "html": "You can select me.
\nYou can't select me!
", "css": ".unselectable {\n user-select: none;\n}", "js": "", "scopedCss": "[data-scope=\"disable-selection\"] .unselectable {\n user-select: none; }\n" }, "tags": [ "interactivity", "beginner" ] }, "meta": { "hash": "717294a4a01093025d81e6cb6a985d9a84849a439495fc0002c7f67e882f95b3", "firstSeen": "1519664998", "lastUpdated": "1588157277", "updateCount": 16, "authorCount": 5 } }, { "id": "display-table-centering", "title": "Display table centering", "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 `| 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",
"codeBlocks": {
"html": " \n ",
"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}",
"js": "",
"scopedCss": "[data-scope=\"display-table-centering\"] .container {\n border: 1px solid #333;\n height: 250px;\n width: 250px; }\n\n[data-scope=\"display-table-centering\"] .center {\n display: table;\n height: 100%;\n width: 100%; }\n\n[data-scope=\"display-table-centering\"] .center > span {\n display: table-cell;\n text-align: center;\n vertical-align: middle; }\n"
},
"tags": [
"layout",
"intermediate"
]
},
"meta": {
"hash": "dc64222bbcae2e2fc731ae08628e140b962719f0734486bc407fd9569e0a1c0a",
"firstSeen": "1522361754",
"lastUpdated": "1588157277",
"updateCount": 16,
"authorCount": 5
}
},
{
"id": "donut-spinner",
"title": "Donut spinner",
"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",
"codeBlocks": {
"html": "",
"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}",
"js": "",
"scopedCss": "@keyframes donut-spin {\n 0% {\n transform: rotate(0deg); }\n 100% {\n transform: rotate(360deg); } }\n\n[data-scope=\"donut-spinner\"] .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"
},
"tags": [
"animation",
"intermediate"
]
},
"meta": {
"hash": "31dfcb657403ccf45f4f0f652cac95505f478a1e5c97ce9b9c3945c2cd6c0fc2",
"firstSeen": "1519745555",
"lastUpdated": "1588157277",
"updateCount": 15,
"authorCount": 4
}
},
{
"id": "drop-cap",
"title": "Drop cap",
"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",
"codeBlocks": {
"html": "Centered content \nLorem 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. \nDonec magna erat, imperdiet non odio sed, sodales tempus magna. Integer vitae orci lectus. Nullam consectetur orci at pellentesque efficitur. ", "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}", "js": "", "scopedCss": "[data-scope=\"drop-cap\"] 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" }, "tags": [ "visual", "beginner" ] }, "meta": { "hash": "29fc5e79e9653ed4bc22e527ed552f9f657861f29acd1302961e0329f2f0052a", "firstSeen": "1539406050", "lastUpdated": "1588157277", "updateCount": 6, "authorCount": 3 } }, { "id": "dynamic-shadow", "title": "Dynamic shadow", "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", "codeBlocks": { "html": "", "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}", "js": "", "scopedCss": "[data-scope=\"dynamic-shadow\"] .dynamic-shadow {\n position: relative;\n width: 10rem;\n height: 10rem;\n background: linear-gradient(75deg, #6d78ff, #00ffb8);\n z-index: 1; }\n\n[data-scope=\"dynamic-shadow\"] .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" }, "tags": [ "visual", "intermediate" ] }, "meta": { "hash": "8f4c102ff96ccb5d6db3007fa587e0e52fcac6950b4d2f55cc897f08627f7cc3", "firstSeen": "1520250696", "lastUpdated": "1588157277", "updateCount": 14, "authorCount": 4 } }, { "id": "easing-variables", "title": "Easing variables", "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 `` element and is identical to the selector `html`, except that its specificity is higher.\n", "codeBlocks": { "html": "Hover ",
"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}",
"js": "",
"scopedCss": "[data-scope=\"easing-variables\"] :root {\n /* Place variables in here to use globally */ }\n\n[data-scope=\"easing-variables\"] .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 --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 --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[data-scope=\"easing-variables\"] .easing-variables:hover {\n transform: rotate(45deg); }\n"
},
"tags": [
"animation",
"beginner"
]
},
"meta": {
"hash": "9f14ed77dd8967cb6ae259832f6dc4d95697220cefc8d0e2464af5d61f0adbbe",
"firstSeen": "1519564479",
"lastUpdated": "1588157277",
"updateCount": 14,
"authorCount": 5
}
},
{
"id": "etched-text",
"title": "Etched text",
"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",
"codeBlocks": {
"html": "I appear etched into the background. ", "css": ".etched-text {\n text-shadow: 0 2px white;\n font-size: 1.5rem;\n font-weight: bold;\n color: #b8bec5;\n}", "js": "", "scopedCss": "[data-scope=\"etched-text\"] .etched-text {\n text-shadow: 0 2px white;\n font-size: 1.5rem;\n font-weight: bold;\n color: #b8bec5; }\n" }, "tags": [ "visual", "intermediate" ] }, "meta": { "hash": "f94e652812b03848e5aff663bdafc1794c5bd3cae64c564041f8f98a9471d182", "firstSeen": "1519564479", "lastUpdated": "1588157277", "updateCount": 14, "authorCount": 4 } }, { "id": "evenly-distributed-children", "title": "Evenly distributed children", "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", "codeBlocks": { "html": "\n ",
"css": ".evenly-distributed-children {\n display: flex;\n justify-content: space-between;\n}",
"js": "",
"scopedCss": "[data-scope=\"evenly-distributed-children\"] .evenly-distributed-children {\n display: flex;\n justify-content: space-between; }\n"
},
"tags": [
"layout",
"intermediate"
]
},
"meta": {
"hash": "dbaab5a8aba16d409371d56ee6923a2b59ed233e145f39419838de76073ccde0",
"firstSeen": "1519818422",
"lastUpdated": "1588157277",
"updateCount": 13,
"authorCount": 4
}
},
{
"id": "fit-image-in-container",
"title": "Fit image in container",
"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",
"codeBlocks": {
"html": "Item1 \nItem2 \nItem3 \n\n ",
"css": ".flexbox-centering {\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100px;\n}",
"js": "",
"scopedCss": "[data-scope=\"flexbox-centering\"] .flexbox-centering {\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100px; }\n"
},
"tags": [
"layout",
"beginner"
]
},
"meta": {
"hash": "53b37c008f374aed5bc8a606e882299adac01d2ae42933963919c92664221d90",
"firstSeen": "1520071047",
"lastUpdated": "1588157277",
"updateCount": 13,
"authorCount": 5
}
},
{
"id": "focus-within",
"title": "Focus Within",
"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",
"codeBlocks": {
"html": "",
"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}",
"js": "",
"scopedCss": "[data-scope=\"focus-within\"] form {\n border: 2px solid #52B882;\n padding: 8px;\n border-radius: 2px; }\n\n[data-scope=\"focus-within\"] form:focus-within {\n background: #7CF0BD; }\n\n[data-scope=\"focus-within\"] label {\n display: inline-block;\n width: 72px; }\n\n[data-scope=\"focus-within\"] input {\n margin: 4px; }\n"
},
"tags": [
"visual",
"interactivity",
"intermediate"
]
},
"meta": {
"hash": "9979d294e5ccc7a4255961c0f0527f9687114973137a5ab3d2bef4828cc65ccf",
"firstSeen": "1540256293",
"lastUpdated": "1588157277",
"updateCount": 14,
"authorCount": 4
}
},
{
"id": "fullscreen",
"title": "Fullscreen",
"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",
"codeBlocks": {
"html": "Centered content. \n\n ",
"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}",
"js": "",
"scopedCss": "[data-scope=\"fullscreen\"] .container {\n margin: 40px auto;\n max-width: 700px; }\n\n[data-scope=\"fullscreen\"] .element {\n padding: 20px;\n height: 300px;\n width: 100%;\n background-color: skyblue;\n box-sizing: border-box; }\n\n[data-scope=\"fullscreen\"] .element p {\n text-align: center;\n color: white;\n font-size: 3em; }\n\n[data-scope=\"fullscreen\"] .element:-ms-fullscreen p {\n visibility: visible; }\n\n[data-scope=\"fullscreen\"] .element:fullscreen {\n background-color: #e4708a;\n width: 100vw;\n height: 100vh; }\n"
},
"tags": [
"visual",
"advanced"
]
},
"meta": {
"hash": "afd6ca97e87bb904559d0913178f8cdc6983785f1100ca71c84ce1747a050923",
"firstSeen": "1547291320",
"lastUpdated": "1588157277",
"updateCount": 11,
"authorCount": 4
}
},
{
"id": "gradient-text",
"title": "Gradient text",
"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",
"codeBlocks": {
"html": "Click the button below to enter the element into fullscreen mode. \nI change color in fullscreen mode! \n \n Gradient text ", "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}", "js": "", "scopedCss": "[data-scope=\"gradient-text\"] .gradient-text {\n background: linear-gradient(#70D6FF, #00072D);\n -webkit-text-fill-color: transparent;\n -webkit-background-clip: text;\n font-size: 32px; }\n" }, "tags": [ "visual", "intermediate" ] }, "meta": { "hash": "66f2df76ea9401a3ac447bf4529ba187f29898d924f4a13f835532c86ee65a6c", "firstSeen": "1519564479", "lastUpdated": "1588157277", "updateCount": 13, "authorCount": 4 } }, { "id": "grid-centering", "title": "Grid centering", "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", "codeBlocks": { "html": "\n ",
"css": ".grid-centering {\n display: grid;\n justify-content: center;\n align-items: center;\n height: 100px;\n}",
"js": "",
"scopedCss": "[data-scope=\"grid-centering\"] .grid-centering {\n display: grid;\n justify-content: center;\n align-items: center;\n height: 100px; }\n"
},
"tags": [
"layout",
"beginner"
]
},
"meta": {
"hash": "f6607d84780e72310e7fab5b71b709bfb4cbfa3ece8cdd5447e151cef3a2eeb3",
"firstSeen": "1520072039",
"lastUpdated": "1588157277",
"updateCount": 14,
"authorCount": 5
}
},
{
"id": "hamburger-button",
"title": "Hamburger Button",
"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",
"codeBlocks": {
"html": "",
"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}",
"js": "",
"scopedCss": "[data-scope=\"hamburger-button\"] .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[data-scope=\"hamburger-button\"] .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[data-scope=\"hamburger-button\"] .hamburger-menu:hover .top {\n transform: rotate(45deg); }\n\n[data-scope=\"hamburger-button\"] .hamburger-menu:hover .middle {\n opacity: 0; }\n\n[data-scope=\"hamburger-button\"] .hamburger-menu:hover .bottom {\n transform: rotate(-45deg); }\n"
},
"tags": [
"interactivity",
"beginner"
]
},
"meta": {
"hash": "deddca92aa1d97b54a0f711185e324142b785ddcbe747756a9bf7b6d861eef3a",
"firstSeen": "1570668578",
"lastUpdated": "1588157277",
"updateCount": 13,
"authorCount": 7
}
},
{
"id": "height-transition",
"title": "Height transition",
"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",
"codeBlocks": {
"html": "Centered content. \n\n Hover me to see a height transition.\n ",
"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}",
"js": "let el = document.querySelector('.el');\nlet height = el.scrollHeight;\nel.style.setProperty('--max-height', height + 'px');",
"scopedCss": "[data-scope=\"height-transition\"] .el {\n transition: max-height 0.5s;\n overflow: hidden;\n max-height: 0; }\n\n[data-scope=\"height-transition\"] .trigger:hover > .el {\n max-height: var(--max-height); }\n"
},
"tags": [
"animation",
"intermediate"
]
},
"meta": {
"hash": "5184cd3ad1c9a8d1cb05ddd5927af34e49727edf1dbf11bf49469c8a89758f0f",
"firstSeen": "1521276782",
"lastUpdated": "1588157277",
"updateCount": 14,
"authorCount": 4
}
},
{
"id": "hover-shadow-box-animation",
"title": "Hover shadow box animation",
"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",
"codeBlocks": {
"html": "Additional content \nBox it! ", "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}", "js": "", "scopedCss": "[data-scope=\"hover-shadow-box-animation\"] .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[data-scope=\"hover-shadow-box-animation\"] .hover-shadow-box-animation:hover,\n[data-scope=\"hover-shadow-box-animation\"] .hover-shadow-box-animation:focus,\n[data-scope=\"hover-shadow-box-animation\"] .hover-shadow-box-animation:active {\n box-shadow: 1px 10px 10px -10px rgba(0, 0, 24, 0.5);\n transform: scale(1.2); }\n" }, "tags": [ "animation", "intermediate" ] }, "meta": { "hash": "eabc2d005a29ead4539ee4ef5c511ed86e0bc64ed1480d69dce23ae3b706f60f", "firstSeen": "1520372515", "lastUpdated": "1588157277", "updateCount": 19, "authorCount": 6 } }, { "id": "hover-underline-animation", "title": "Hover underline animation", "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", "codeBlocks": { "html": "Hover this text to see the effect! ", "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}", "js": "", "scopedCss": "[data-scope=\"hover-underline-animation\"] .hover-underline-animation {\n display: inline-block;\n position: relative;\n color: #0087ca; }\n\n[data-scope=\"hover-underline-animation\"] .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[data-scope=\"hover-underline-animation\"] .hover-underline-animation:hover:after {\n transform: scaleX(1);\n transform-origin: bottom left; }\n" }, "tags": [ "animation", "advanced" ] }, "meta": { "hash": "0478f301d7055ab1d351cf38ed9a2ae4410bc5ad62c9f5304bf58184174e5ee1", "firstSeen": "1519816762", "lastUpdated": "1588157277", "updateCount": 19, "authorCount": 4 } }, { "id": "image-hover-menu", "title": "Menu on image hover", "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", "codeBlocks": { "html": " \n\t\n \n \n Lorem \n |