1602 lines
117 KiB
JSON
1602 lines
117 KiB
JSON
{
|
|
"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#### HTML\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 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",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"border-with-top-triangle\"] .container {\n position: relative;\n background: #ffffff;\n padding: 15px;\n border: 1px solid #dddddd;\n margin-top: 20px; }\n\n[data-scope=\"border-with-top-triangle\"] .container:before, [data-scope=\"border-with-top-triangle\"] .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[data-scope=\"border-with-top-triangle\"] .container:after {\n left: 20px;\n border: 10px solid transparent;\n border-bottom-color: #ffffff; }\n"
|
|
},
|
|
"tags": [
|
|
"visual",
|
|
"beginner"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "4fed80c83d37457d5ce111ee5c3272945c203319ccc4f5fe4355c359840f8628",
|
|
"firstSeen": "1547806723",
|
|
"lastUpdated": "1569668086",
|
|
"updateCount": 3
|
|
}
|
|
},
|
|
{
|
|
"id": "bouncing-loader",
|
|
"title": "Bouncing loader",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "bouncing-loader.md",
|
|
"text": "Creates a bouncing loader animation.\n\n",
|
|
"explanation": "\n\nNote: `1rem` is usually `16px`.\n\n1. `@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.\n2. `.bouncing-loader` is the parent container of the bouncing circles and uses `display: flex` and `justify-content: center` to position them in the center.\n3. `.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.\n4. `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.\n5. `animation` is a shorthand property for the various animation properties: `animation-name`, `animation-duration`, `animation-iteration-count`, `animation-direction` are used.\n6. `nth-child(n)` targets the element which is the nth child of its parent.\n7. `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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-animation\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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.bouncing-loader {\n display: flex;\n justify-content: center;\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.bouncing-loader > div:nth-child(2) {\n animation-delay: 0.2s;\n}\n.bouncing-loader > div:nth-child(3) {\n animation-delay: 0.4s;\n}",
|
|
"js": "",
|
|
"scopedCss": "@keyframes bouncing-loader {\n to {\n opacity: 0.1;\n transform: translate3d(0, -1rem, 0); } }\n\n[data-scope=\"bouncing-loader\"] .bouncing-loader {\n display: flex;\n justify-content: center; }\n\n[data-scope=\"bouncing-loader\"] .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[data-scope=\"bouncing-loader\"] .bouncing-loader > div:nth-child(2) {\n animation-delay: 0.2s; }\n\n[data-scope=\"bouncing-loader\"] .bouncing-loader > div:nth-child(3) {\n animation-delay: 0.4s; }\n"
|
|
},
|
|
"tags": [
|
|
"animation"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "2934b3aa733591f4964a7c8780f3ec7b273e4bd6a38fce6e0da2a5dd2dd9959f",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "box-sizing-reset",
|
|
"title": "Box-sizing reset",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "box-sizing-reset.md",
|
|
"text": "Resets the box-model so that `width`s and `height`s are not affected by their `border`s or `padding`.\n\n",
|
|
"explanation": "\n\n1. `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.\n2. `box-sizing: inherit` makes an element respect its parent's `box-sizing` rule.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css3-boxsizing\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"box\">border-box</div>\n<div class=\"box content-box\">content-box</div>",
|
|
"css": "html {\n box-sizing: border-box;\n}\n*,\n*::before,\n*::after {\n box-sizing: inherit;\n}\n.box {\n display: inline-block;\n width: 150px;\n height: 150px;\n padding: 10px;\n background: tomato;\n color: white;\n border: 10px solid red;\n}\n.content-box {\n box-sizing: content-box;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"box-sizing-reset\"] html {\n box-sizing: border-box; }\n\n[data-scope=\"box-sizing-reset\"] *,\n[data-scope=\"box-sizing-reset\"] *::before,\n[data-scope=\"box-sizing-reset\"] *::after {\n box-sizing: inherit; }\n\n[data-scope=\"box-sizing-reset\"] .box {\n display: inline-block;\n width: 150px;\n height: 150px;\n padding: 10px;\n background: tomato;\n color: white;\n border: 10px solid red; }\n\n[data-scope=\"box-sizing-reset\"] .content-box {\n box-sizing: content-box; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "d4e635bb76a083266e08723f25c3db981b39001ea5d513ce65570fe0099eb6b0",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "button-border-animation",
|
|
"title": "Button border animation",
|
|
"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` pseduo-elements as borders that animate on hover.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"button-border\"><button class=\"button\">Submit</button></div>",
|
|
"css": ".button {\n background-color: #c47135;\n border: none;\n color: #ffffff;\n outline: none;\n padding: 12px 40px 10px;\n position: relative;\n}\n.button:before,\n.button:after {\n border: 0 solid transparent;\n transition: all 0.25s;\n content: '';\n height: 24px;\n position: absolute;\n width: 24px;\n}\n.button:before {\n border-top: 2px solid #c47135;\n left: 0px;\n top: -5px;\n}\n.button:after {\n border-bottom: 2px solid #c47135;\n bottom: -5px;\n right: 0px;\n}\n.button:hover {\n background-color: #c47135;\n}\n.button:hover:before,\n.button:hover:after {\n height: 100%;\n width: 100%;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"button-border-animation\"] .button {\n background-color: #c47135;\n border: none;\n color: #ffffff;\n outline: none;\n padding: 12px 40px 10px;\n position: relative; }\n\n[data-scope=\"button-border-animation\"] .button:before,\n[data-scope=\"button-border-animation\"] .button:after {\n border: 0 solid transparent;\n transition: all 0.25s;\n content: '';\n height: 24px;\n position: absolute;\n width: 24px; }\n\n[data-scope=\"button-border-animation\"] .button:before {\n border-top: 2px solid #c47135;\n left: 0px;\n top: -5px; }\n\n[data-scope=\"button-border-animation\"] .button:after {\n border-bottom: 2px solid #c47135;\n bottom: -5px;\n right: 0px; }\n\n[data-scope=\"button-border-animation\"] .button:hover {\n background-color: #c47135; }\n\n[data-scope=\"button-border-animation\"] .button:hover:before,\n[data-scope=\"button-border-animation\"] .button:hover:after {\n height: 100%;\n width: 100%; }\n"
|
|
},
|
|
"tags": [
|
|
"animation"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "ff6401cc784b92a9672e74968719c029de224c29fcfdc3eaeaa764274108f648",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "calc",
|
|
"title": "Calc()",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "calc.md",
|
|
"text": "The function calc() allows to define CSS values with the use of mathematical expressions, the value adopted for the property is the result of a mathematical expression.\n\n",
|
|
"explanation": "\n\n1. It allows addition, subtraction, multiplication and division.\n2. Can use different units (pixel and percent together, for example) for each value in your expression.\n3. It is permitted to nest calc() functions.\n4. It can be used in any property that `<length>`, `<frequency>`, `<angle>`, `<time>`, `<number>`, `<color>`, or `<integer>` is allowed, like width, height, font-size, top, left, etc.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=calc\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"box-example\"></div>",
|
|
"css": ".box-example {\n height: 280px;\n background: #222 url('https://image.ibb.co/fUL9nS/wolf.png') no-repeat;\n background-position: calc(100% - 20px) calc(100% - 20px);\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"calc\"] .box-example {\n height: 280px;\n background: #222 url(\"https://image.ibb.co/fUL9nS/wolf.png\") no-repeat;\n background-position: calc(100% - 20px) calc(100% - 20px); }\n"
|
|
},
|
|
"tags": [
|
|
"other"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "8165e64d1bca7ae3bb0c990712023720dff55c2f6194b557a131901d528be4b7",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "circle",
|
|
"title": "Circle",
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=border-radius\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"circle\"></div>",
|
|
"css": ".circle {\n border-radius: 50%;\n width: 2rem;\n height: 2rem;\n background: #333;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"circle\"] .circle {\n border-radius: 50%;\n width: 2rem;\n height: 2rem;\n background: #333; }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "60ac5a7cb7e2c24c936b267ac74d649052c9aaa80810278720b5b5a14fee1562",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "clearfix",
|
|
"title": "Clearfix",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "clearfix.md",
|
|
"text": "Ensures that an element self-clears its children.\n\n###### Note: 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.\n\n",
|
|
"explanation": "\n\n1. `.clearfix::after` defines a pseudo-element.\n2. `content: ''` allows the pseudo-element to affect layout.\n3. `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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ 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).</span>\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"clearfix\"] .clearfix::after {\n content: '';\n display: block;\n clear: both; }\n\n[data-scope=\"clearfix\"] .floated {\n float: left; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "55fe4fad743f778816b5923c862484cfa84efd353a4d2a3efe04893db6f5863f",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "constant-width-to-height-ratio",
|
|
"title": "Constant width to height ratio",
|
|
"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\n(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\n",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"constant-width-to-height-ratio\"></div>",
|
|
"css": ".constant-width-to-height-ratio {\n background: #333;\n width: 50%;\n}\n.constant-width-to-height-ratio::before {\n content: '';\n padding-top: 100%;\n float: left;\n}\n.constant-width-to-height-ratio::after {\n content: '';\n display: block;\n clear: both;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"constant-width-to-height-ratio\"] .constant-width-to-height-ratio {\n background: #333;\n width: 50%; }\n\n[data-scope=\"constant-width-to-height-ratio\"] .constant-width-to-height-ratio::before {\n content: '';\n padding-top: 100%;\n float: left; }\n\n[data-scope=\"constant-width-to-height-ratio\"] .constant-width-to-height-ratio::after {\n content: '';\n display: block;\n clear: both; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "931815035291ba0e6de497d7296fc75e207117c9ff0607fd646f01da53793929",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "counter",
|
|
"title": "Counter",
|
|
"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\n- You can create a ordered list using any type of HTML.\n\n1. `counter-reset` Initializes a counter, the value is the name of the counter. By default, the counter starts at 0. This property can also be used to change its value to any specific number.\n2. `counter-increment` Used in element that will be countable. Once `counter-reset` initialized, a counter's value can be increased or decreased.\n3. `counter(name, style)` Displays the value of a section counter. Generally used in a `content` property. This function can receive two parameters, the first as the name of the counter and the second one can be `decimal` or `upper-roman` (`decimal` by default).\n4. `counters(counter, string, style)` Displays the value of a section counter. Generally used in a `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).\n5. 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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-counters\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"counter\"] ul {\n counter-reset: counter; }\n\n[data-scope=\"counter\"] li::before {\n counter-increment: counter;\n content: counters(counter, \".\") \" \"; }\n"
|
|
},
|
|
"tags": [
|
|
"visual",
|
|
"other"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "7c572c339c0767840bd0fd6f5daab357a8da070988c621e341bc5ce78d0f798e",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "custom-scrollbar",
|
|
"title": "Custom scrollbar",
|
|
"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\n1. `::-webkit-scrollbar` targets the whole scrollbar element.\n2. `::-webkit-scrollbar-track` targets only the scrollbar track.\n3. `::-webkit-scrollbar-thumb` targets the scrollbar thumb.\n\nThere 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",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Scrollbar styling doesn't appear to be on any standards track.</span>\n\n- https://caniuse.com/#feat=css-scrollbar\n",
|
|
"supportPercentage": 97.69
|
|
},
|
|
"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/* To style the document scrollbar, remove `.custom-scrollbar` */\n\n.custom-scrollbar::-webkit-scrollbar {\n width: 8px;\n}\n\n.custom-scrollbar::-webkit-scrollbar-track {\n box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);\n border-radius: 10px;\n}\n\n.custom-scrollbar::-webkit-scrollbar-thumb {\n border-radius: 10px;\n box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"custom-scrollbar\"] {\n /* To style the document scrollbar, remove `.custom-scrollbar` */ }\n [data-scope=\"custom-scrollbar\"] .custom-scrollbar {\n height: 70px;\n overflow-y: scroll; }\n [data-scope=\"custom-scrollbar\"] .custom-scrollbar::-webkit-scrollbar {\n width: 8px; }\n [data-scope=\"custom-scrollbar\"] .custom-scrollbar::-webkit-scrollbar-track {\n box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);\n border-radius: 10px; }\n [data-scope=\"custom-scrollbar\"] .custom-scrollbar::-webkit-scrollbar-thumb {\n border-radius: 10px;\n box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5); }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "e5544c894ee3cd4ce3352d10331e2f321c6d30b4a0a667434286c6d4951c3b0a",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "custom-text-selection",
|
|
"title": "Custom text selection",
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires prefixes for full support and is not actually\nin any specification.</span>\n\n- https://caniuse.com/#feat=css-selection\n",
|
|
"supportPercentage": 90.1
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<p class=\"custom-text-selection\">Select some of this text.</p>",
|
|
"css": "::selection {\n background: aquamarine;\n color: black;\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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "bf835c2f1d038e6b08d221c9fef85933757a80c67de555797c6bc63ff7035ae8",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "custom-variables",
|
|
"title": "Custom variables",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "custom-variables.md",
|
|
"text": "CSS variables that contain specific values to be reused throughout a document.\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. Variables can also be scoped to a selector if defined within the block.\n- Declare a variable with `--variable-name:`.\n- Reuse variables throughout the document using the `var(--variable-name)` function.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-variables\n",
|
|
"supportPercentage": 96.51
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<p class=\"custom-variables\">CSS is awesome!</p>",
|
|
"css": ":root {\n /* Place variables within here to use the variables globally. */\n}\n\n.custom-variables {\n --some-color: #da7800;\n --some-keyword: italic;\n --some-size: 1.25em;\n --some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;\n color: var(--some-color);\n font-size: var(--some-size);\n font-style: var(--some-keyword);\n text-shadow: var(--some-complex-value);\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"custom-variables\"] :root {\n /* Place variables within here to use the variables globally. */ }\n\n[data-scope=\"custom-variables\"] .custom-variables {\n --some-color: #da7800;\n --some-keyword: italic;\n --some-size: 1.25em;\n --some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;\n color: var(--some-color);\n font-size: var(--some-size);\n font-style: var(--some-keyword);\n text-shadow: var(--some-complex-value); }\n"
|
|
},
|
|
"tags": [
|
|
"other"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "7a0d1c46beceb336265b2ca27a4f3cf25ad332a5cd2e8c0b692a43ce5b329fef",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires prefixes for full support.</span>\n<br>\n<span class=\"snippet__support-note\">⚠️ This is not a secure method to prevent users from copying content.</span>\n\n- https://caniuse.com/#feat=user-select-none\n",
|
|
"supportPercentage": 97.51
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"disable-selection\"] .unselectable {\n user-select: none; }\n"
|
|
},
|
|
"tags": [
|
|
"interactivity"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "02f6472568975f5897a84f8846d97f8561fc5334ddafac53e73adb52ccda5f29",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n1. `display: table` on '.center' allows the element to behave like a `<table>` HTML element.\n2. 100% height and width on '.center' allows the element to fill the available space within its parent element.\n3. `display: table-cell` on '.center > span' allows the element to behave like an <td> HTML element.\n4. `text-align: center` on '.center > span' centers the child element horizontally.\n5. `vertical-align: middle` on '.center > span' centers the child element vertically.\n\n- The outer parent ('.container' in this case) must have a fixed height and width.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#search=display%3A%20table\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "83c7806b0be2e50ca34f313912f9cb90682852790e6d0105a635f781212fa5b1",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires prefixes for full support.</span>\n\n- https://caniuse.com/#feat=css-animation\n- https://caniuse.com/#feat=transforms2d\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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.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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "4e7f5ce479955deb9830ca4a72fc8260c8863aa65d6f67f15e88a3f923c10c3a",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=first-letter\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"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": "e7859bc139713ffe59a05904f6175e9578ad111ebe3405d58599846c44801606",
|
|
"firstSeen": "1539406050",
|
|
"lastUpdated": "1569669005",
|
|
"updateCount": 4
|
|
}
|
|
},
|
|
{
|
|
"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\n1. `position: relative` on the element establishes a Cartesian positioning context for psuedo-elements.\n2. `z-index: 1` establishes a new stacking context.\n3. `::after` defines a pseudo-element.\n4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n5. `width: 100%` and `height: 100%` sizes the pseudo-element to fill its parent's dimensions, making it equal in size.\n6. `background: inherit` causes the pseudo-element to inherit the linear gradient specified on the element.\n7. `top: 0.5rem` offsets the pseudo-element down slightly from its parent.\n8. `filter: blur(0.4rem)` will blur the pseudo-element to create the appearance of a shadow underneath.\n9. `opacity: 0.7` makes the pseudo-element partially transparent.\n10. `z-index: -1` positions the pseudo-element behind the parent but in front of the background.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires prefixes for full support.</span>\n\n- https://caniuse.com/#feat=css-filters\n",
|
|
"supportPercentage": 98.46
|
|
},
|
|
"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.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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "738fae9ee6d0a9fe84cdbdd632a93f651f8377ec7e9f647e1031207d99b819a5",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\npowerful 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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-variables\n",
|
|
"supportPercentage": 96.51
|
|
},
|
|
"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}",
|
|
"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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "94ec3c4e6b02374b61367e8cf4edcb9532bb7297673a28acaee0ad3264adfa3d",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-textshadow\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "68da5c2e7399979db3aeb1022d13b0490fc71d55d068597544954706c7027bef",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n1. `display: flex` enables flexbox.\n2. `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\n- Alternatively, use `justify-content: space-around` to distribute the children with space around them, rather than between them.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Needs prefixes for full support.</span>\n\n- https://caniuse.com/#feat=flexbox\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"evenly-distributed-children\"] .evenly-distributed-children {\n display: flex;\n justify-content: space-between; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "86c8c53be49e82365f6d6f54a03b55d9a8888ccc85504fe0480499b0e68c7f5b",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=object-fit\n",
|
|
"supportPercentage": 99.5
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"fit-image-in-container\"] .image {\n background: #34495e;\n border: 1px solid #34495e;\n width: 200px;\n height: 200px; }\n\n[data-scope=\"fit-image-in-container\"] .image-contain {\n object-fit: contain;\n object-position: center; }\n\n[data-scope=\"fit-image-in-container\"] .image-cover {\n object-fit: cover;\n object-position: right top; }\n"
|
|
},
|
|
"tags": [
|
|
"layout",
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "5d09d5e54b7436f047db61223cff15dce2f17f6cffe5e71e0f9061337de3068e",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "flexbox-centering",
|
|
"title": "Flexbox centering",
|
|
"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\n1. `display: flex` enables flexbox.\n2. `justify-content: center` centers the child horizontally.\n3. `align-items: center` centers the child vertically.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Needs prefixes for full support.</span>\n\n- https://caniuse.com/#feat=flexbox\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"flexbox-centering\"><div class=\"child\">Centered content.</div></div>",
|
|
"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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "a2bf8cfa4de368cfb10d013b6bbb87c598e0cccacfe816972da4ac668c6abc1a",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Not supported in IE11 or the current version of Edge.</span>\n\n<!-- Whenever possible, link a `caniuse` feature which allows the browser support percentage to be displayed.\nIf no link is provided, it defaults to 99+%. -->\n\n- https://caniuse.com/#feat=css-focus-within\n",
|
|
"supportPercentage": 85.39
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"focus-within\">\n <form>\n <label for=\"given_name\">Given Name:</label> <input id=\"given_name\" type=\"text\" /> <br />\n <label for=\"family_name\">Family Name:</label> <input id=\"family_name\" type=\"text\" />\n </form>\n</div>",
|
|
"css": "form {\n border: 3px solid #2d98da;\n color: #000000;\n padding: 4px;\n}\n\nform:focus-within {\n background: #f7b731;\n color: #000000;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"focus-within\"] form {\n border: 3px solid #2d98da;\n color: #000000;\n padding: 4px; }\n\n[data-scope=\"focus-within\"] form:focus-within {\n background: #f7b731;\n color: #000000; }\n"
|
|
},
|
|
"tags": [
|
|
"visual",
|
|
"interactivity"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "a12b394af0b2df2f7fa6bae2cbbe3a8b01ba74510991dcfe3952b8bd9c0a5a41",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "fullscreen",
|
|
"title": "Fullscreen",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "fullscreen.md",
|
|
"text": "The :fullscreen CSS pseudo-class represents an element that's displayed when the browser is in fullscreen mode.\n\n",
|
|
"explanation": "\n\n1. `fullscreen` CSS pseudo-class selector is used to select and style an element that is being displayed in fullscreen mode.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://developer.mozilla.org/en-US/docs/Web/CSS/:fullscreen\n- https://caniuse.com/#feat=fullscreen\n",
|
|
"supportPercentage": 99.11
|
|
},
|
|
"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}",
|
|
"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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "23cab923692f5e3250be38b3c970dc11f3bab34159812aaf979ea09bce441c30",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567144393",
|
|
"updateCount": 3
|
|
}
|
|
},
|
|
{
|
|
"id": "ghost-trick",
|
|
"title": "Ghost trick",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "ghost-trick.md",
|
|
"text": "Vertically centers an element in another.\n\n",
|
|
"explanation": "\n\n- Use the style of a `:before` pseudo-element to vertically align inline elements without changing their `position` property.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=inline-block\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"ghost-trick\">\n <div class=\"ghosting\"><p>Vertically centered without changing the position property.</p></div>\n</div>",
|
|
"css": ".ghosting {\n height: 300px;\n background: #0ff;\n}\n\n.ghosting:before {\n content: '';\n display: inline-block;\n height: 100%;\n vertical-align: middle;\n}\n\np {\n display: inline-block;\n vertical-align: middle;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"ghost-trick\"] .ghosting {\n height: 300px;\n background: #0ff; }\n\n[data-scope=\"ghost-trick\"] .ghosting:before {\n content: '';\n display: inline-block;\n height: 100%;\n vertical-align: middle; }\n\n[data-scope=\"ghost-trick\"] p {\n display: inline-block;\n vertical-align: middle; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "0515f03b1505eafa21e0d0d7377facbe4aaa9159996906dd4ed2857ee137073a",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "gradient-text",
|
|
"title": "Gradient text",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "gradient-text.md",
|
|
"text": "Gives text a gradient color.\n\n",
|
|
"explanation": "\n\n1. `background: -webkit-linear-gradient(...)` gives the text element a gradient background.\n2. `webkit-text-fill-color: transparent` fills the text with a transparent color.\n3. `webkit-background-clip: text` clips the background with the text, filling the text with the gradient background as the color.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Uses non-standard properties.</span>\n\n- https://caniuse.com/#feat=text-stroke\n",
|
|
"supportPercentage": 98.65
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<p class=\"gradient-text\">Gradient text</p>",
|
|
"css": ".gradient-text {\n background: -webkit-linear-gradient(pink, red);\n -webkit-text-fill-color: transparent;\n -webkit-background-clip: text;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"gradient-text\"] .gradient-text {\n background: -webkit-linear-gradient(pink, red);\n -webkit-text-fill-color: transparent;\n -webkit-background-clip: text; }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "9620da48fb82b48a7c6b681854707b622a18c158f2db88c816e3b9c0d9b04523",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n1. `display: grid` enables grid.\n2. `justify-content: center` centers the child horizontally.\n3. `align-items: center` centers the child vertically.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-grid\n",
|
|
"supportPercentage": 97.25999999999999
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"grid-centering\"><div class=\"child\">Centered content.</div></div>",
|
|
"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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "f6fbb076581e63ab9187ca63d8620f88de19d7a78c46f9ded903271461a445bf",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "hairline-border",
|
|
"title": "Hairline border",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "hairline-border.md",
|
|
"text": "Gives an element a border equal to 1 native device pixel in width, which can look\nvery sharp and crisp.\n\n",
|
|
"explanation": "\n\n1. `box-shadow`, when only using spread, adds a pseudo-border which can use subpixels\\*.\n2. Use `@media (min-resolution: ...)` to check the device pixel ratio (`1dppx` equals 96 DPI), setting the spread of the `box-shadow` equal to `1 / dppx`.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Needs alternate syntax and JavaScript user agent checking for full support.</span>\n\n- https://caniuse.com/#feat=css-boxshadow\n- https://caniuse.com/#feat=css-media-resolution\n\n<hr>\n\n\\*Chrome does not support subpixel values on `border`. Safari does not support subpixel values on `box-shadow`. Firefox supports subpixel values on both.\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"hairline-border\">text</div>",
|
|
"css": ".hairline-border {\n box-shadow: 0 0 0 1px;\n}\n\n@media (min-resolution: 2dppx) {\n .hairline-border {\n box-shadow: 0 0 0 0.5px;\n }\n}\n\n@media (min-resolution: 3dppx) {\n .hairline-border {\n box-shadow: 0 0 0 0.33333333px;\n }\n}\n\n@media (min-resolution: 4dppx) {\n .hairline-border {\n box-shadow: 0 0 0 0.25px;\n }\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"hairline-border\"] .hairline-border {\n box-shadow: 0 0 0 1px; }\n\n@media (min-resolution: 2dppx) {\n [data-scope=\"hairline-border\"] .hairline-border {\n box-shadow: 0 0 0 0.5px; } }\n\n@media (min-resolution: 3dppx) {\n [data-scope=\"hairline-border\"] .hairline-border {\n box-shadow: 0 0 0 0.33333333px; } }\n\n@media (min-resolution: 4dppx) {\n [data-scope=\"hairline-border\"] .hairline-border {\n box-shadow: 0 0 0 0.25px; } }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "cd26d0cd1831474afdc784b4459b60062243e2d390975e94cd7d51fa776c603f",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "hamburger-button",
|
|
"title": "Hamburger Button",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "hamburger-button.md",
|
|
"text": "This is a way to build simple hamburger button for menu bar.\n\n",
|
|
"explanation": "\n\n- Use a `<button>` element for the middle bar of the hamburger icon.\n- Use the `::before` and `::after` pseudo-elements to create the top and bottom bars of the icon.\n- Use `position: relative` on the `<button>` and `position: absolute` on the pseudo-elements to place them appropriately.\n- Use the `:hover` pseudo-selector to rotate `:before` to `45deg` and `:after` to `-45deg` and hide the center bar using`:background-color` transparent.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<button class=\"hb\"></button>",
|
|
"css": ".hb,\n.hb:before,\n.hb:after {\n position: relative;\n width: 30px;\n height: 5px;\n border: none;\n outline: none;\n background-color: #333;\n border-radius: 3px;\n transition: 0.5s;\n cursor: pointer;\n}\n\n.hb:before,\n.hb:after {\n content: '';\n position: absolute;\n top: -7.5px;\n left: 0;\n}\n\n.hb:after {\n top: 7.5px;\n}\n\n.hb:hover {\n background-color: transparent;\n}\n\n.hb:hover:before,\n.hb:hover:after {\n top: 0;\n}\n\n.hb:hover::before {\n transform: rotate(45deg);\n}\n\n.hb:hover::after {\n transform: rotate(-45deg);\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"hamburger-button\"] .hb,\n[data-scope=\"hamburger-button\"] .hb:before,\n[data-scope=\"hamburger-button\"] .hb:after {\n position: relative;\n width: 30px;\n height: 5px;\n border: none;\n outline: none;\n background-color: #333;\n border-radius: 3px;\n transition: 0.5s;\n cursor: pointer; }\n\n[data-scope=\"hamburger-button\"] .hb:before,\n[data-scope=\"hamburger-button\"] .hb:after {\n content: '';\n position: absolute;\n top: -7.5px;\n left: 0; }\n\n[data-scope=\"hamburger-button\"] .hb:after {\n top: 7.5px; }\n\n[data-scope=\"hamburger-button\"] .hb:hover {\n background-color: transparent; }\n\n[data-scope=\"hamburger-button\"] .hb:hover:before,\n[data-scope=\"hamburger-button\"] .hb:hover:after {\n top: 0; }\n\n[data-scope=\"hamburger-button\"] .hb:hover::before {\n transform: rotate(45deg); }\n\n[data-scope=\"hamburger-button\"] .hb:hover::after {\n transform: rotate(-45deg); }\n"
|
|
},
|
|
"tags": [
|
|
"interactivity",
|
|
"beginner"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "952fe17aa1f9856b3976d74578db84e409a7439d0ded80195b7d5420ea95d5ae",
|
|
"firstSeen": "1570668578",
|
|
"lastUpdated": "1573762725",
|
|
"updateCount": 6
|
|
}
|
|
},
|
|
{
|
|
"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\n1. `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.\n2. `overflow: hidden` prevents the contents of the hidden element from overflowing its container.\n3. `max-height: 0` specifies that the element has no height initially.\n4. `.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\n---\n\n1. `el.scrollHeight` is the height of the element including overflow, which will change dynamically based on the content of the element.\n2. `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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<div class=\"snippet__requires-javascript\">Requires JavaScript</div>\n<span class=\"snippet__support-note\">\n ⚠️ Causes reflow on each animation frame, which will be laggy if there are a large number of elements\n beneath the element that is transitioning in height.\n</span>\n\n- https://caniuse.com/#feat=css-variables\n- https://caniuse.com/#feat=css-transitions\n",
|
|
"supportPercentage": 96.51
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"trigger\">\n Hover me to see a height transition.\n <div class=\"el\">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}",
|
|
"js": "var el = document.querySelector('.el')\nvar 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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "bff0b57d24dac06ae6a6d71a8d0d628ec0b97760be0cfda66791191957075d73",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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\n1. `display: inline-block` to set width and length for `p` element thus making it an `inline-block`.\n2. 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.\n3. `box-shadow:` to set up the box.\n4. `transparent` to make box transparent.\n5. `transition-property` to enable transitions for both `box-shadow` and `transform`.\n6. `:hover` to activate whole css when hovering is done until `active`.\n7. `transform: scale(1.2)` to change the scale, magnifying the text.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=transforms3d\n- https://caniuse.com/#feat=css-transitions\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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.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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "4136aff34ae1b8bf6b525c08881a12c43e9ce7265e864c09ea25fa40e8d86396",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"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<small>**Credit:** https://flatuicolors.com/</small>\n\n",
|
|
"explanation": "\n\n1. `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).\n2. `position: relative` on the element establishes a Cartesian positioning context for pseudo-elements.\n3. `::after` defines a pseudo-element.\n4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n5. `width: 100%` ensures the pseudo-element spans the entire width of the text block.\n6. `transform: scaleX(0)` initially scales the pseudo element to 0 so it has no width and is not visible.\n7. `bottom: 0` and `left: 0` position it to the bottom left of the block.\n8. `transition: transform 0.25s ease-out` means changes to `transform` will be transitioned over 0.25 seconds with an `ease-out` timing function.\n9. `transform-origin: bottom right` means the transform anchor point is positioned at the bottom right of the block.\n10. `: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",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=transforms2d\n- https://caniuse.com/#feat=css-transitions\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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.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.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"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "6e8a53b0b69ab05f54c199f42944746c0e3331712f69a8dc72709eda16428424",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "last-item-with-remaining-available-height",
|
|
"title": "Last item with remaining available height",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "last-item-with-remaining-available-height.md",
|
|
"text": "Take advantage of available viewport space by giving the last element the remaining available space in current viewport, even when resizing the window.\n\n",
|
|
"explanation": "\n\n1. `height: 100%` set the height of container as viewport height.\n2. `display: flex` enables flexbox.\n3. `flex-direction: column` set the direction of flex items' order from top to down.\n4. `flex-grow: 1` the flexbox will apply remaining available space of container to last child element.\n\n- The parent must have a viewport height. `flex-grow: 1` could be applied to the first or second element, which will have all available space.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Needs prefixes for full support.</span>\n\n- https://caniuse.com/#feat=flexbox\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"container\">\n <div>Div 1</div>\n <div>Div 2</div>\n <div>Div 3</div>\n</div>",
|
|
"css": "html,\nbody {\n height: 100%;\n margin: 0;\n}\n\n.container {\n height: 100%;\n display: flex;\n flex-direction: column;\n}\n\n.container > div:last-child {\n background-color: tomato;\n flex: 1;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"last-item-with-remaining-available-height\"] html,\n[data-scope=\"last-item-with-remaining-available-height\"] body {\n height: 100%;\n margin: 0; }\n\n[data-scope=\"last-item-with-remaining-available-height\"] .container {\n height: 100%;\n display: flex;\n flex-direction: column; }\n\n[data-scope=\"last-item-with-remaining-available-height\"] .container > div:last-child {\n background-color: tomato;\n flex: 1; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "2f925cc190a9744532de97bb4add65e53cc0b2f3833760f4e7263f5df17cfad5",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "lobotomizedOwlSelector",
|
|
"title": "Lobotomized Owl Selector",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "lobotomizedOwlSelector.md",
|
|
"text": "Sets an automatically inherited margin for all elements that follow other elements in the document.\n\n",
|
|
"explanation": "\n\n- [View this link for a detailed explanation.](https://alistapart.com/article/axiomatic-css-and-lobotomized-owls/)\n- In this example, all elements in the flow of the document that follow other elements will receive `margin-top: 1.5em`.\n- This example assumes that the paragraphs' `font-size` is 1em and its `line-height` is 1.5.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div>\n <div>Parent 01</div>\n <div>Parent 02\n <div>Child 01</div>\n <div>Child 02</div>\n </div>\n <div>Parent 03</div>\n</div>",
|
|
"css": "* + * {\n margin-top: 1.5em;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"lobotomizedOwlSelector\"] * + * {\n margin-top: 1.5em; }\n"
|
|
},
|
|
"tags": [
|
|
"layout",
|
|
"beginner"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "e0cd9ededcfb68d085f6a1fbdc63fba65cee9adc13c08a458f73b0fbaf0f5949",
|
|
"firstSeen": "1569946901",
|
|
"lastUpdated": "1569946901",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "mouse-cursor-gradient-tracking",
|
|
"title": "Mouse cursor gradient tracking",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "mouse-cursor-gradient-tracking.md",
|
|
"text": "A hover effect where the gradient follows the mouse cursor.\n\n<small class=\"snippet__credit\">**Credit:** [Tobias Reich](https://codepen.io/electerious/pen/MQrRxX)</small>\n\n",
|
|
"explanation": "\n\n1. `--x` and `--y` are used to track the position of the mouse on the button.\n2. `--size` is used to keep modify of the gradient's dimensions.\n3. `background: radial-gradient(circle closest-side, pink, transparent);` creates the gradient at the correct postion.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires JavaScript.</span>\n\n- https://caniuse.com/#feat=css-variables\n",
|
|
"supportPercentage": 96.51
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<button class=\"mouse-cursor-gradient-tracking\"><span>Hover me</span></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}",
|
|
"js": "var btn = document.querySelector('.mouse-cursor-gradient-tracking')\nbtn.onmousemove = function(e) {\n var rect = e.target.getBoundingClientRect()\n var x = e.clientX - rect.left\n var y = e.clientY - rect.top\n btn.style.setProperty('--x', x + 'px')\n btn.style.setProperty('--y', y + 'px')\n}",
|
|
"scopedCss": "[data-scope=\"mouse-cursor-gradient-tracking\"] .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[data-scope=\"mouse-cursor-gradient-tracking\"] .mouse-cursor-gradient-tracking span {\n position: relative; }\n\n[data-scope=\"mouse-cursor-gradient-tracking\"] .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[data-scope=\"mouse-cursor-gradient-tracking\"] .mouse-cursor-gradient-tracking:hover::before {\n --size: 200px; }\n"
|
|
},
|
|
"tags": [
|
|
"visual",
|
|
"interactivity"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "97fbac82b526cafe6e48233dda46d0bb87fde7a52027774048b90c9c14818395",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567151937",
|
|
"updateCount": 3
|
|
}
|
|
},
|
|
{
|
|
"id": "navigation-list-item-hover-and-focus-effect",
|
|
"title": "Navigation list item hover and focus effect",
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=transforms2d\n- https://caniuse.com/#feat=css-transitions\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<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": "nav ul {\n list-style: none;\n margin: 0;\n padding: 0;\n overflow: hidden;\n}\n\nnav li {\n float: left;\n}\n\nnav 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, li a:focus::before {\n transform: scale(1);\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"navigation-list-item-hover-and-focus-effect\"] nav ul {\n list-style: none;\n margin: 0;\n padding: 0;\n overflow: hidden; }\n\n[data-scope=\"navigation-list-item-hover-and-focus-effect\"] nav li {\n float: left; }\n\n[data-scope=\"navigation-list-item-hover-and-focus-effect\"] 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[data-scope=\"navigation-list-item-hover-and-focus-effect\"] li 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[data-scope=\"navigation-list-item-hover-and-focus-effect\"] li a:hover::before, [data-scope=\"navigation-list-item-hover-and-focus-effect\"] li a:focus::before {\n transform: scale(1); }\n"
|
|
},
|
|
"tags": [
|
|
"visual",
|
|
"beginner"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "9e2cbf0541001ebaaa5584e8d4e7f68e5f436e79574ec9c62facd20962bfa87a",
|
|
"firstSeen": "1568922537",
|
|
"lastUpdated": "1569825639",
|
|
"updateCount": 4
|
|
}
|
|
},
|
|
{
|
|
"id": "not-selector",
|
|
"title": ":not selector",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "not-selector.md",
|
|
"text": "The `:not` pseudo selector is useful for styling a group of elements, while leaving the last (or specified) element unstyled.\n\n",
|
|
"explanation": "\n\n- `li:not(:last-child)` specifies that the styles should apply to all `li` elements except the `:last-child`.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-sel3\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<ul class=\"css-not-selector-shortcut\">\n <li>One</li>\n <li>Two</li>\n <li>Three</li>\n <li>Four</li>\n</ul>",
|
|
"css": ".css-not-selector-shortcut {\n display: flex;\n}\n\nul {\n padding-left: 0;\n}\n\nli {\n list-style-type: none;\n margin: 0;\n padding: 0 0.75rem;\n}\n\nli:not(:last-child) {\n border-right: 2px solid #d2d5e4;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"not-selector\"] .css-not-selector-shortcut {\n display: flex; }\n\n[data-scope=\"not-selector\"] ul {\n padding-left: 0; }\n\n[data-scope=\"not-selector\"] li {\n list-style-type: none;\n margin: 0;\n padding: 0 0.75rem; }\n\n[data-scope=\"not-selector\"] li:not(:last-child) {\n border-right: 2px solid #d2d5e4; }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "847dbaae8802781fa073cc92c6891ea0a0c39752f95266fcb4db7812dc78640e",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1569415890",
|
|
"updateCount": 3
|
|
}
|
|
},
|
|
{
|
|
"id": "offscreen",
|
|
"title": "Offscreen",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "offscreen.md",
|
|
"text": "A bulletproof way to completely hide an element visually and positionally in the DOM while still allowing it to be accessed by JavaScript and readable by screen readers. This method is very useful for accessibility ([ADA](https://adata.org/learn-about-ada)) development when more context is needed for visually-impaired users. As an alternative to `display: none` which is not readable by screen readers or `visibility: hidden` which takes up physical space in the DOM.\n\n",
|
|
"explanation": "\n\n1. Remove all borders.\n2. Use `clip` to indicate that no part of the element should be shown.\n3. Make the height and width of the element 1px.\n4. Negate the elements height and width using `margin: -1px`.\n5. Hide the element's overflow.\n6. Remove all padding.\n7. Position the element absolutely so that it does not take up space in the DOM.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n(Although `clip` technically has been depreciated, the newer `clip-path` currently has very limited browser support.)\n\n- https://caniuse.com/#search=clip\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"offscreen\"] .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"
|
|
},
|
|
"tags": [
|
|
"layout",
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "a718446c91f49c73e68bc4f317911ff03f898ac8efe0e832ca1f803709107820",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1571634867",
|
|
"updateCount": 3
|
|
}
|
|
},
|
|
{
|
|
"id": "overflow-scroll-gradient",
|
|
"title": "Overflow scroll gradient",
|
|
"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\n1. `position: relative` on the parent establishes a Cartesian positioning context for pseudo-elements.\n2. `::after` defines a pseudo element.\n3. `background-image: linear-gradient(...)` adds a linear gradient that fades from transparent to white (top to bottom).\n4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n5. `width: 240px` matches the size of the scrolling element (which is a child of the parent that has the pseudo element).\n6. `height: 25px` is the height of the fading gradient pseudo-element, which should be kept relatively small.\n7. `bottom: 0` positions the pseudo-element at the bottom of the parent.\n8. `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",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-gradients\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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.overflow-scroll-gradient::after {\n content: '';\n position: absolute;\n bottom: 0;\n width: 250px;\n height: 25px;\n background: linear-gradient(\n rgba(255, 255, 255, 0.001),\n white\n ); /* transparent keyword is broken in Safari */\n pointer-events: none;\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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"overflow-scroll-gradient\"] .overflow-scroll-gradient {\n position: relative; }\n\n[data-scope=\"overflow-scroll-gradient\"] .overflow-scroll-gradient::after {\n content: '';\n position: absolute;\n bottom: 0;\n width: 250px;\n height: 25px;\n background: linear-gradient(rgba(255, 255, 255, 0.001), white);\n /* transparent keyword is broken in Safari */\n pointer-events: none; }\n\n[data-scope=\"overflow-scroll-gradient\"] .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"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "e25bdb353dc5da5c1c359f91769d85d0b3b0a58ff7085041603e4e685b380ef7",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567155517",
|
|
"updateCount": 3
|
|
}
|
|
},
|
|
{
|
|
"id": "popout-menu",
|
|
"title": "Popout menu",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "popout-menu.md",
|
|
"text": "Reveals an interactive popout menu on hover and focus.\n\n",
|
|
"explanation": "\n\n1. `position: relative` on the reference parent establishes a Cartesian positioning context for its child.\n2. `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.\n3. `left: 100%` moves the the popout menu 100% of its parent's width from the left.\n4. `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).\n5. `.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.\n6. `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.\n7. `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is _within_ the reference.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"reference\" tabindex=\"0\"><div class=\"popout-menu\">Popout menu</div></div>",
|
|
"css": ".reference {\n position: relative;\n background: tomato;\n width: 100px;\n height: 100px;\n}\n.popout-menu {\n position: absolute;\n visibility: hidden;\n left: 100%;\n background: #333;\n color: white;\n padding: 15px;\n}\n.reference:hover > .popout-menu,\n.reference:focus > .popout-menu,\n.reference:focus-within > .popout-menu {\n visibility: visible;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"popout-menu\"] .reference {\n position: relative;\n background: tomato;\n width: 100px;\n height: 100px; }\n\n[data-scope=\"popout-menu\"] .popout-menu {\n position: absolute;\n visibility: hidden;\n left: 100%;\n background: #333;\n color: white;\n padding: 15px; }\n\n[data-scope=\"popout-menu\"] .reference:hover > .popout-menu,\n[data-scope=\"popout-menu\"] .reference:focus > .popout-menu,\n[data-scope=\"popout-menu\"] .reference:focus-within > .popout-menu {\n visibility: visible; }\n"
|
|
},
|
|
"tags": [
|
|
"interactivity"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "46d1f9e1a05328d86ffda0dbea7dc60eae44c319eb430632ef384d2f3e7e6d44",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "pretty-text-underline",
|
|
"title": "Pretty text underline",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "pretty-text-underline.md",
|
|
"text": "A nicer alternative to `text-decoration: underline` or `<u></u>` 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\n1. `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.\n2. `background-image: linear-gradient(...)` creates a 90deg gradient using the text color (`currentColor`).\n3. 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.\n4. The `::selection` pseudo selector rule ensures the text shadow does not interfere with text selection.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-textshadow\n- https://caniuse.com/#feat=css-gradients\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<p class=\"pretty-text-underline\">Pretty text underline without clipping descending letters.</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.pretty-text-underline::-moz-selection {\n background-color: rgba(0, 150, 255, 0.3);\n text-shadow: none;\n}\n.pretty-text-underline::selection {\n background-color: rgba(0, 150, 255, 0.3);\n text-shadow: none;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"pretty-text-underline\"] .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[data-scope=\"pretty-text-underline\"] .pretty-text-underline::-moz-selection {\n background-color: rgba(0, 150, 255, 0.3);\n text-shadow: none; }\n\n[data-scope=\"pretty-text-underline\"] .pretty-text-underline::selection {\n background-color: rgba(0, 150, 255, 0.3);\n text-shadow: none; }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "fb3a96cbbb4d59af2566f3d0729c13478a81a572b25a8dd1696e2a67dd8fff79",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "pulse-loader",
|
|
"title": "Pulse loader",
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-animation\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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 #76ff03;\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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"pulse-loader\"] .ripple-loader {\n position: relative;\n width: 64px;\n height: 64px; }\n\n[data-scope=\"pulse-loader\"] .ripple-loader div {\n position: absolute;\n border: 4px solid #76ff03;\n border-radius: 50%;\n animation: ripple-loader 1s ease-out infinite; }\n\n[data-scope=\"pulse-loader\"] .ripple-loader div:nth-child(2) {\n animation-delay: -0.5s; }\n\n@keyframes ripple-loader {\n 0% {\n top: 32px;\n left: 32px;\n width: 0;\n height: 0;\n opacity: 1; }\n 100% {\n top: 0;\n left: 0;\n width: 64px;\n height: 64px;\n opacity: 0; } }\n"
|
|
},
|
|
"tags": [
|
|
"animation",
|
|
"beginner"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "11f0b0631cb97ab53a144c263648c155527e570e0ceefaea59201c39de73b57b",
|
|
"firstSeen": "1570274976",
|
|
"lastUpdated": "1570335973",
|
|
"updateCount": 4
|
|
}
|
|
},
|
|
{
|
|
"id": "reset-all-styles",
|
|
"title": "Reset all styles",
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ MS Edge status is under consideration.</span>\n\n- https://caniuse.com/#feat=css-all\n",
|
|
"supportPercentage": 95.76
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"reset-all-styles\"] .reset-all-styles {\n all: initial; }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "f9542b2db5cd49f09e53b3af8348c58c973244bdeede87857e49660c6e713d65",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "shape-separator",
|
|
"title": "Shape separator",
|
|
"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\n1. `position: relative` on the element establishes a Cartesian positioning context for pseudo elements.\n2. `::after` defines a pseudo element.\n3. `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/).\n4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.\n5. `width: 100%` ensures the element stretches the entire width of its parent.\n6. `height: 12px` is the same height as the shape.\n7. `bottom: 0` positions the pseudo element at the bottom of the parent.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=svg\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"shape-separator\"></div>",
|
|
"css": ".shape-separator {\n position: relative;\n height: 48px;\n background: #333;\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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"shape-separator\"] .shape-separator {\n position: relative;\n height: 48px;\n background: #333; }\n\n[data-scope=\"shape-separator\"] .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"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "0b86c444f4d15709a99d1e32c651e9530a294258ba32784d998a56c6f14198b1",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "sibling-fade",
|
|
"title": "Sibling fade",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "sibling-fade.md",
|
|
"text": "Fades out the siblings of a hovered item.\n\n",
|
|
"explanation": "\n\n1. `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.2 seconds.\n2. `.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",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-sel3\n- https://caniuse.com/#feat=css-transitions\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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.2s;\n}\n\n.sibling-fade:hover span:not(:hover) {\n opacity: 0.5;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"sibling-fade\"] span {\n padding: 0 1rem;\n transition: opacity 0.2s; }\n\n[data-scope=\"sibling-fade\"] .sibling-fade:hover span:not(:hover) {\n opacity: 0.5; }\n"
|
|
},
|
|
"tags": [
|
|
"interactivity"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "35bfb52929dcbd21c120d555c9d3382154f47b661d31722ffb3d21281021bba3",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "system-font-stack",
|
|
"title": "System font stack",
|
|
"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\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\n1. `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however)\n2. `BlinkMacSystemFont` is San Francisco, used on macOS Chrome\n3. `Segoe UI` is used on Windows 10\n4. `Roboto` is used on Android\n5. `Oxygen-Sans` is used on Linux with KDE\n6. `Ubuntu` is used on Ubuntu (all variants)\n7. `Cantarell` is used on Linux with GNOME Shell\n8. `\"Helvetica Neue\"` and `Helvetica` is used on macOS 10.10 and below (wrapped in quotes because it has a space)\n9. `Arial` is a font widely supported by all operating systems\n10. `sans-serif` is the fallback sans-serif font if none of the other fonts are supported\n\n",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"system-font-stack\"] .system-font-stack {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif; }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "97b037f3f463b8cf7de0cc12a607c540ffe8a4869323a4cc17c66eebbc92d612",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "tile-layout-using-inline-block",
|
|
"title": "3-tile layout",
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://www.caniuse.com/#search=inline-block\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"tiles\">\n <div class=\"tile\">\n <img class=\"tile_image\" src=\"https://via.placeholder.com/250x150\" alt=\"placeholder\" >\n <h2 class=\"tile_title\">30 Seconds of CSS</h2>\n </div>\n <div class=\"tile\">\n <img class=\"tile_image\" src=\"https://via.placeholder.com/250x150\" alt=\"placeholder\" >\n <h2 class=\"tile_title\">30 Seconds of CSS</h2>\n </div>\n <div class=\"tile\">\n <img class=\"tile_image\" src=\"https://via.placeholder.com/250x150\" alt=\"placeholder\" >\n <h2 class=\"tile_title\">30 Seconds of CSS</h2>\n </div>\n</div>",
|
|
"css": ".tiles {\n width: 900px;\n font-size: 0;\n}\n\n.tile {\n width: calc(900px / 3);\n display: inline-block;\n}\n\n.tile h2 {\n font-size: 20px;\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"tile-layout-using-inline-block\"] .tiles {\n width: 900px;\n font-size: 0; }\n\n[data-scope=\"tile-layout-using-inline-block\"] .tile {\n width: calc(900px / 3);\n display: inline-block; }\n\n[data-scope=\"tile-layout-using-inline-block\"] .tile h2 {\n font-size: 20px; }\n"
|
|
},
|
|
"tags": [
|
|
"layout",
|
|
"beginner"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "ba4688945c309db9b6255f4555299034a67ea583e4e8db2806085c1c257b736f",
|
|
"firstSeen": "1569999119",
|
|
"lastUpdated": "1569999119",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "toggle-switch",
|
|
"title": "Toggle switch",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "toggle-switch.md",
|
|
"text": "Creates a toggle switch with CSS only.\n\n",
|
|
"explanation": "\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\n1. The `for` attribute associates the `<label>` with the appropriate `<input>` checkbox element by its `id`.\n2. `.switch::after` defines a pseudo-element for the `<label>` to create the circular knob.\n3. `input[type='checkbox']:checked + .switch::after` targets the `<label>`'s pseudo-element's style when the checkbox is `checked`.\n4. `transform: translateX(20px)` moves the pseudo-element (knob) 20px to the right when the checkbox is `checked`.\n5. `background-color: #7983ff;` sets the background-color of the switch to a different color when the checkbox is `checked`.\n6. `.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.\n7. `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",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires prefixes for full support.</span>\n\n- https://caniuse.com/#feat=transforms2d\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"toggle-switch\"] .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[data-scope=\"toggle-switch\"] .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[data-scope=\"toggle-switch\"] input[type='checkbox']:checked + .switch::after {\n transform: translateX(20px); }\n\n[data-scope=\"toggle-switch\"] input[type='checkbox']:checked + .switch {\n background-color: #7983ff; }\n\n[data-scope=\"toggle-switch\"] .offscreen {\n position: absolute;\n left: -9999px; }\n"
|
|
},
|
|
"tags": [
|
|
"visual",
|
|
"interactivity"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "e29182514bd83550705267a43d21eec8886ed011c6259f2b3efec9862541f90e",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "transform-centering",
|
|
"title": "Transform centering",
|
|
"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\n1. `position: absolute` on the child element allows it to be positioned based on its containing block.\n2. `left: 50%` and `top: 50%` offsets the child 50% from the left and top edge of its containing block.\n3. `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\n- Note: that the fixed height and width on parent element is for the demo only.\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires prefix for full support.</span>\n\n- https://caniuse.com/#feat=transforms2d\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"parent\"><div class=\"child\">Centered content</div></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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"transform-centering\"] .parent {\n border: 1px solid #333;\n height: 250px;\n position: relative;\n width: 250px; }\n\n[data-scope=\"transform-centering\"] .child {\n left: 50%;\n position: absolute;\n top: 50%;\n transform: translate(-50%, -50%);\n text-align: center; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "9ee4bb8713d24b9e6f5367eb05645c6e41d205b120b4d06a9a949984c7cd73b0",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "transform-detransform",
|
|
"title": "Transform - Detransform",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "transform-detransform.md",
|
|
"text": "Sets a transform on the parent element and de-transforms the child elements, so they are not affected by the transform.\nThis allows for some neat effects such as skewed buttons.\n\n",
|
|
"explanation": "\n\n- `--transform: 10deg` sets a CSS variable we can later use to prevent duplicate code.\n- `calc(-1 * var(--transform))` on the child element negates the transform from the parent.\n\n- Note: the `display` property of the child element may not be `inline`, otherwise the transform will be ignored ([see also](https://drafts.csswg.org/css-transforms-1/#terminology)).\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Requires prefix for full support.</span>\n\n- https://caniuse.com/#feat=transforms2d\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"codeBlocks": {
|
|
"html": "<div class=\"parent\"><div class=\"child\">Child content</div></div>",
|
|
"css": ":root {\n --transform: 10deg;\n}\n\n.parent {\n transform: skewX(var(--transform));\n padding: 1rem;\n border: 1px solid;\n display: inline-block;\n}\n\n.child {\n transform: skewX(calc(-1 * var(--transform)));\n}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"transform-detransform\"] :root {\n --transform: 10deg; }\n\n[data-scope=\"transform-detransform\"] .parent {\n transform: skewX(var(--transform));\n padding: 1rem;\n border: 1px solid;\n display: inline-block; }\n\n[data-scope=\"transform-detransform\"] .child {\n transform: skewX(calc(-1 * var(--transform))); }\n"
|
|
},
|
|
"tags": [
|
|
"visual",
|
|
"beginner"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "3d669f655ec92a355b355d2d35e6e9262ad582671abac860d7170893ac68e467",
|
|
"firstSeen": "1571344652",
|
|
"lastUpdated": "1571344652",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "triangle",
|
|
"title": "Triangle",
|
|
"type": "snippet",
|
|
"attributes": {
|
|
"fileName": "triangle.md",
|
|
"text": "Creates a triangle shape with pure CSS.\n\n",
|
|
"explanation": "\n\n- [View this link for a detailed explanation.](https://stackoverflow.com/q/7073484)\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",
|
|
"browserSupport": {
|
|
"text": "\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"triangle\"] .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"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "357daaf44bab240518a3c9bdd34a1e8702fab3358171e30f633b7a7f423b9884",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "truncate-text-multiline",
|
|
"title": "Truncate text multiline",
|
|
"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\n1. `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).\n2. `width: 400px` ensures the element has a dimension.\n3. `height: 109.2px` calculated value for height, it equals `font-size * line-height * numberOfLines` (in this case `26 * 1.4 * 3 = 109.2`)\n4. `height: 36.4px` calculated value for gradient container, it equals `font-size * line-height` (in this case `26 * 1.4 = 36.4`)\n5. `background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%)` gradient from `transparent` to `#f5f6f9`\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n- https://caniuse.com/#feat=css-gradients\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"truncate-text-multiline\"] .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[data-scope=\"truncate-text-multiline\"] .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"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "a30287149e833b454deea446359d51554640ad3a57cd2460d8519c376077b8b4",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "truncate-text",
|
|
"title": "Truncate text",
|
|
"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\n1. `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).\n2. `white-space: nowrap` prevents the text from exceeding one line in height.\n3. `text-overflow: ellipsis` makes it so that if the text exceeds its dimensions, it will end with an ellipsis.\n4. `width: 200px;` ensures the element has a dimension, to know when to get ellipsis\n\n",
|
|
"browserSupport": {
|
|
"text": "\n\n<span class=\"snippet__support-note\">⚠️ Only works for single line elements.</span>\n\n- https://caniuse.com/#feat=text-overflow\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"truncate-text\"] .truncate-text {\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n width: 200px; }\n"
|
|
},
|
|
"tags": [
|
|
"layout"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "4ce872446c7950c9450e56ab2251c7cfcd473a1c9b2a64baa7c9d6b029264796",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
},
|
|
{
|
|
"id": "zebra-striped-list",
|
|
"title": "Zebra striped list",
|
|
"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\n",
|
|
"browserSupport": {
|
|
"text": "\n\nhttps://caniuse.com/#feat=css-sel3\n",
|
|
"supportPercentage": 100
|
|
},
|
|
"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}",
|
|
"js": "",
|
|
"scopedCss": "[data-scope=\"zebra-striped-list\"] li:nth-child(odd) {\n background-color: #ddd; }\n"
|
|
},
|
|
"tags": [
|
|
"visual"
|
|
]
|
|
},
|
|
"meta": {
|
|
"hash": "43bc0cd7776468f3b74791017349ef278921c8ded7ba0bd7788d2b01bdb68c7a",
|
|
"firstSeen": "1567098430",
|
|
"lastUpdated": "1567098430",
|
|
"updateCount": 2
|
|
}
|
|
}
|
|
],
|
|
"meta": {
|
|
"specification": "http://jsonapi.org/format/",
|
|
"type": "snippetArray",
|
|
"language": {
|
|
"short": "css",
|
|
"long": "CSS"
|
|
},
|
|
"otherLanguages": [
|
|
{
|
|
"short": "html",
|
|
"long": "HTML"
|
|
},
|
|
{
|
|
"short": "js",
|
|
"long": "JavaScript"
|
|
}
|
|
]
|
|
}
|
|
} |