├── .gitattributes ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── languageFix.css ├── logo.png ├── snippet-template.md └── snippets ├── aspect-ratio.md ├── border-with-top-triangle.md ├── bouncing-loader.md ├── box-sizing-reset.md ├── broken-image-fallback.md ├── button-border-animation.md ├── button-focus-swing-animation.md ├── button-hover-fill-animation.md ├── button-hover-grow-animation.md ├── button-hover-shrink-animation.md ├── card-image-cutout.md ├── checkerboard-pattern.md ├── circle.md ├── clearfix.md ├── constant-width-to-height-ratio.md ├── counter.md ├── custom-checkbox.md ├── custom-radio.md ├── custom-scrollbar.md ├── custom-text-selection.md ├── disable-selection.md ├── display-empty-links.md ├── display-table-centering.md ├── donut-spinner.md ├── drop-cap.md ├── dynamic-shadow.md ├── etched-text.md ├── evenly-distributed-children.md ├── fit-image-in-container.md ├── flexbox-centering.md ├── floating-list-titles.md ├── fluid-typography.md ├── focus-within.md ├── full-width.md ├── fullscreen.md ├── gradient-text.md ├── grid-centering.md ├── hamburger-button.md ├── height-transition.md ├── hide-empty-elements.md ├── hide-scrollbars.md ├── horizontal-gallery.md ├── horizontal-scroll-snap.md ├── hover-additional-content.md ├── hover-perspective.md ├── hover-shadow-box-animation.md ├── hover-underline-animation.md ├── image-hover-menu.md ├── image-hover-rotate.md ├── image-mosaic.md ├── image-overlay-hover.md ├── image-text-overlay.md ├── input-with-prefix.md ├── isometric-card.md ├── line-clamp.md ├── masonry-layout.md ├── mouse-cursor-gradient-tracking.md ├── navigation-list-item-hover-and-focus-effect.md ├── offscreen.md ├── overflow-scroll-gradient.md ├── polka-dot-pattern.md ├── popout-menu.md ├── pretty-text-underline.md ├── pulse-loader.md ├── reset-all-styles.md ├── responsive-layout-sidebar.md ├── rotating-card.md ├── scroll-progress-bar.md ├── shake-invalid-input.md ├── shape-separator.md ├── shifting-card.md ├── sibling-fade.md ├── squiggle-link-hover-effect.md ├── staggered-animation.md ├── sticky-list-titles.md ├── stripes-pattern.md ├── stylized-quotation-marks.md ├── system-font-stack.md ├── text-backdrop-overlay.md ├── tile-layout-using-inline-block.md ├── toggle-switch.md ├── transform-centering.md ├── triangle.md ├── truncate-text-multiline.md ├── truncate-text.md ├── typewriter-effect.md ├── vertical-gallery.md ├── vertical-scroll-snap.md ├── zebra-striped-list.md ├── zig-zag-pattern.md └── zoomin-zoomout-animation.md /.gitattributes: -------------------------------------------------------------------------------- 1 | src/docs/* linguist-documentation 2 | scripts/* linguist-documentation 3 | gatsby-browser.js linguist-documentation 4 | gatsby-config.js linguist-documentation 5 | gatsby-node.js linguist-documentation 6 | gatsby-ssr.js linguist-documentation 7 | .travis/* linguist-documentation 8 | config.js linguist-documentation 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn 55 | yarn-error.log 56 | .pnp/ 57 | .pnp.js 58 | 59 | # Yarn Integrity file 60 | .yarn-integrity 61 | 62 | # dotenv environment variables file 63 | .env 64 | 65 | # next.js build output 66 | .next 67 | 68 | # gatsby files 69 | .cache/ 70 | public 71 | 72 | # Mac files 73 | .DS_Store -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | - Using welcoming and inclusive language 12 | - Being respectful of differing viewpoints and experiences 13 | - Gracefully accepting constructive criticism 14 | - Focusing on what is best for the community 15 | - Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | - Trolling, insulting/derogatory comments, and personal or political attacks 21 | - Public or private harassment 22 | - Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | - Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at cc.glows@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | **30 seconds of code** is powered by the community, so feel free to contribute in any way you can to help us! 4 | ## How you can help 5 | 6 | - Submit pull requests with new snippets (see guidelines below) or snippet updates (tags, descriptions, explanations, typos, examples, code improvements). 7 | - Open issues for things you want to see added, modified, discuss ideas or help out with existing issues. 8 | 9 | ## Ground rules 10 | 11 | Breaking any of these rules will result in your pull request being closed. Please follow these guidelines above all else: 12 | 13 | - **Always be polite and respectful to others** and try to follow the advice of the moderators/collaborators/owners. 14 | - **Only modify snippet files**, never modify the generated files in the `snippet_data` directory. 15 | - **Use the snippet template** to create new snippets, ensure they have the correct name and are in the correct location. 16 | - **Follow snippet format exactly**, otherwise your snippets will not be recognized correctly by the tools responsible for publishing them on the website. This includes such things as spacing and empty lines - if you accidentally make a mistake, consult the repository's [snippet template](snippet-template.md). 17 | - **Snippets should solve real-world problems**, no matter how simple and should be abstract enough to be applied to different scenarios. 18 | 19 | ## Snippet creation 20 | 21 | In order to create a new snippet, you should follow the steps below: 22 | 23 | - Create a copy of the [snippet template](snippet-template.md) in the `snippets` directory. 24 | - Change the name of the newly created file to the name of your snippet. 25 | - Edit the file, adding your snippet based on the guidelines. 26 | 27 | ## Snippet guidelines 28 | 29 | - Snippet must follow [these general writing guidelines](https://github.com/30-seconds/brand-and-design/blob/master/writing-guidelines.md). 30 | - Snippets must have all their frontmatter sections (title, tags etc.) filled. 31 | - Snippet titles must correspond to the filename and follow the language and repository's naming conventions. 32 | - Snippet tags must be comma-separated, contain a primary tag as seen on the website as their first tag. 33 | - Snippets must have their `firstSeen` dates formatted using [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601). 34 | - Snippet descriptions must be short and to the point. Explain *what* the snippet does and detail *how* the snippet works and the language features used in it. Snippet description should be written as lists of points (unordered for a few points, ordered otherwise), describing the implemented functionality. 35 | - Snippet code and examples must be enclosed in appropriate, language-tagged blocks as shown in the snippet template, be short and use modern techniques and features. Also make sure to test your code before submitting. 36 | - If your snippet contains arguments with default parameters, explain what happens if they are omitted when calling the function and what the default case is. Specify default parameters for arguments only if necessary. 37 | - If your snippet uses recursion, use the `recursion` tag and explain the base cases. 38 | - Try to strike a balance between readability, brevity, and performance. 39 | - Always use soft tabs (2 spaces), never hard tabs. 40 | - Leave a single space after a comma (`,`) character (both in the description and code). 41 | - Define multiple variables on the same line, if possible. Use meaningful names (e.g. `letter` instead of `lt`) and follow existing conventions as seen in other snippets. Do not use trailing or leading underscores in variable names. 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution 4.0 International Public License 58 | 59 | By exercising the Licensed Rights (defined below), You accept and agree 60 | to be bound by the terms and conditions of this Creative Commons 61 | Attribution 4.0 International Public License ("Public License"). To the 62 | extent this Public License may be interpreted as a contract, You are 63 | granted the Licensed Rights in consideration of Your acceptance of 64 | these terms and conditions, and the Licensor grants You such rights in 65 | consideration of benefits the Licensor receives from making the 66 | Licensed Material available under these terms and conditions. 67 | 68 | 69 | Section 1 -- Definitions. 70 | 71 | a. Adapted Material means material subject to Copyright and Similar 72 | Rights that is derived from or based upon the Licensed Material 73 | and in which the Licensed Material is translated, altered, 74 | arranged, transformed, or otherwise modified in a manner requiring 75 | permission under the Copyright and Similar Rights held by the 76 | Licensor. For purposes of this Public License, where the Licensed 77 | Material is a musical work, performance, or sound recording, 78 | Adapted Material is always produced where the Licensed Material is 79 | synched in timed relation with a moving image. 80 | 81 | b. Adapter's License means the license You apply to Your Copyright 82 | and Similar Rights in Your contributions to Adapted Material in 83 | accordance with the terms and conditions of this Public License. 84 | 85 | c. Copyright and Similar Rights means copyright and/or similar rights 86 | closely related to copyright including, without limitation, 87 | performance, broadcast, sound recording, and Sui Generis Database 88 | Rights, without regard to how the rights are labeled or 89 | categorized. For purposes of this Public License, the rights 90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 91 | Rights. 92 | 93 | d. Effective Technological Measures means those measures that, in the 94 | absence of proper authority, may not be circumvented under laws 95 | fulfilling obligations under Article 11 of the WIPO Copyright 96 | Treaty adopted on December 20, 1996, and/or similar international 97 | agreements. 98 | 99 | e. Exceptions and Limitations means fair use, fair dealing, and/or 100 | any other exception or limitation to Copyright and Similar Rights 101 | that applies to Your use of the Licensed Material. 102 | 103 | f. Licensed Material means the artistic or literary work, database, 104 | or other material to which the Licensor applied this Public 105 | License. 106 | 107 | g. Licensed Rights means the rights granted to You subject to the 108 | terms and conditions of this Public License, which are limited to 109 | all Copyright and Similar Rights that apply to Your use of the 110 | Licensed Material and that the Licensor has authority to license. 111 | 112 | h. Licensor means the individual(s) or entity(ies) granting rights 113 | under this Public License. 114 | 115 | i. Share means to provide material to the public by any means or 116 | process that requires permission under the Licensed Rights, such 117 | as reproduction, public display, public performance, distribution, 118 | dissemination, communication, or importation, and to make material 119 | available to the public including in ways that members of the 120 | public may access the material from a place and at a time 121 | individually chosen by them. 122 | 123 | j. Sui Generis Database Rights means rights other than copyright 124 | resulting from Directive 96/9/EC of the European Parliament and of 125 | the Council of 11 March 1996 on the legal protection of databases, 126 | as amended and/or succeeded, as well as other essentially 127 | equivalent rights anywhere in the world. 128 | 129 | k. You means the individual or entity exercising the Licensed Rights 130 | under this Public License. Your has a corresponding meaning. 131 | 132 | 133 | Section 2 -- Scope. 134 | 135 | a. License grant. 136 | 137 | 1. Subject to the terms and conditions of this Public License, 138 | the Licensor hereby grants You a worldwide, royalty-free, 139 | non-sublicensable, non-exclusive, irrevocable license to 140 | exercise the Licensed Rights in the Licensed Material to: 141 | 142 | a. reproduce and Share the Licensed Material, in whole or 143 | in part; and 144 | 145 | b. produce, reproduce, and Share Adapted Material. 146 | 147 | 2. Exceptions and Limitations. For the avoidance of doubt, where 148 | Exceptions and Limitations apply to Your use, this Public 149 | License does not apply, and You do not need to comply with 150 | its terms and conditions. 151 | 152 | 3. Term. The term of this Public License is specified in Section 153 | 6(a). 154 | 155 | 4. Media and formats; technical modifications allowed. The 156 | Licensor authorizes You to exercise the Licensed Rights in 157 | all media and formats whether now known or hereafter created, 158 | and to make technical modifications necessary to do so. The 159 | Licensor waives and/or agrees not to assert any right or 160 | authority to forbid You from making technical modifications 161 | necessary to exercise the Licensed Rights, including 162 | technical modifications necessary to circumvent Effective 163 | Technological Measures. For purposes of this Public License, 164 | simply making modifications authorized by this Section 2(a) 165 | (4) never produces Adapted Material. 166 | 167 | 5. Downstream recipients. 168 | 169 | a. Offer from the Licensor -- Licensed Material. Every 170 | recipient of the Licensed Material automatically 171 | receives an offer from the Licensor to exercise the 172 | Licensed Rights under the terms and conditions of this 173 | Public License. 174 | 175 | b. No downstream restrictions. You may not offer or impose 176 | any additional or different terms or conditions on, or 177 | apply any Effective Technological Measures to, the 178 | Licensed Material if doing so restricts exercise of the 179 | Licensed Rights by any recipient of the Licensed 180 | Material. 181 | 182 | 6. No endorsement. Nothing in this Public License constitutes or 183 | may be construed as permission to assert or imply that You 184 | are, or that Your use of the Licensed Material is, connected 185 | with, or sponsored, endorsed, or granted official status by, 186 | the Licensor or others designated to receive attribution as 187 | provided in Section 3(a)(1)(A)(i). 188 | 189 | b. Other rights. 190 | 191 | 1. Moral rights, such as the right of integrity, are not 192 | licensed under this Public License, nor are publicity, 193 | privacy, and/or other similar personality rights; however, to 194 | the extent possible, the Licensor waives and/or agrees not to 195 | assert any such rights held by the Licensor to the limited 196 | extent necessary to allow You to exercise the Licensed 197 | Rights, but not otherwise. 198 | 199 | 2. Patent and trademark rights are not licensed under this 200 | Public License. 201 | 202 | 3. To the extent possible, the Licensor waives any right to 203 | collect royalties from You for the exercise of the Licensed 204 | Rights, whether directly or through a collecting society 205 | under any voluntary or waivable statutory or compulsory 206 | licensing scheme. In all other cases the Licensor expressly 207 | reserves any right to collect such royalties. 208 | 209 | 210 | Section 3 -- License Conditions. 211 | 212 | Your exercise of the Licensed Rights is expressly made subject to the 213 | following conditions. 214 | 215 | a. Attribution. 216 | 217 | 1. If You Share the Licensed Material (including in modified 218 | form), You must: 219 | 220 | a. retain the following if it is supplied by the Licensor 221 | with the Licensed Material: 222 | 223 | i. identification of the creator(s) of the Licensed 224 | Material and any others designated to receive 225 | attribution, in any reasonable manner requested by 226 | the Licensor (including by pseudonym if 227 | designated); 228 | 229 | ii. a copyright notice; 230 | 231 | iii. a notice that refers to this Public License; 232 | 233 | iv. a notice that refers to the disclaimer of 234 | warranties; 235 | 236 | v. a URI or hyperlink to the Licensed Material to the 237 | extent reasonably practicable; 238 | 239 | b. indicate if You modified the Licensed Material and 240 | retain an indication of any previous modifications; and 241 | 242 | c. indicate the Licensed Material is licensed under this 243 | Public License, and include the text of, or the URI or 244 | hyperlink to, this Public License. 245 | 246 | 2. You may satisfy the conditions in Section 3(a)(1) in any 247 | reasonable manner based on the medium, means, and context in 248 | which You Share the Licensed Material. For example, it may be 249 | reasonable to satisfy the conditions by providing a URI or 250 | hyperlink to a resource that includes the required 251 | information. 252 | 253 | 3. If requested by the Licensor, You must remove any of the 254 | information required by Section 3(a)(1)(A) to the extent 255 | reasonably practicable. 256 | 257 | 4. If You Share Adapted Material You produce, the Adapter's 258 | License You apply must not prevent recipients of the Adapted 259 | Material from complying with this Public License. 260 | 261 | 262 | Section 4 -- Sui Generis Database Rights. 263 | 264 | Where the Licensed Rights include Sui Generis Database Rights that 265 | apply to Your use of the Licensed Material: 266 | 267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 268 | to extract, reuse, reproduce, and Share all or a substantial 269 | portion of the contents of the database; 270 | 271 | b. if You include all or a substantial portion of the database 272 | contents in a database in which You have Sui Generis Database 273 | Rights, then the database in which You have Sui Generis Database 274 | Rights (but not its individual contents) is Adapted Material; and 275 | 276 | c. You must comply with the conditions in Section 3(a) if You Share 277 | all or a substantial portion of the contents of the database. 278 | 279 | For the avoidance of doubt, this Section 4 supplements and does not 280 | replace Your obligations under this Public License where the Licensed 281 | Rights include other Copyright and Similar Rights. 282 | 283 | 284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 285 | 286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 296 | 297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 306 | 307 | c. The disclaimer of warranties and limitation of liability provided 308 | above shall be interpreted in a manner that, to the extent 309 | possible, most closely approximates an absolute disclaimer and 310 | waiver of all liability. 311 | 312 | 313 | Section 6 -- Term and Termination. 314 | 315 | a. This Public License applies for the term of the Copyright and 316 | Similar Rights licensed here. However, if You fail to comply with 317 | this Public License, then Your rights under this Public License 318 | terminate automatically. 319 | 320 | b. Where Your right to use the Licensed Material has terminated under 321 | Section 6(a), it reinstates: 322 | 323 | 1. automatically as of the date the violation is cured, provided 324 | it is cured within 30 days of Your discovery of the 325 | violation; or 326 | 327 | 2. upon express reinstatement by the Licensor. 328 | 329 | For the avoidance of doubt, this Section 6(b) does not affect any 330 | right the Licensor may have to seek remedies for Your violations 331 | of this Public License. 332 | 333 | c. For the avoidance of doubt, the Licensor may also offer the 334 | Licensed Material under separate terms or conditions or stop 335 | distributing the Licensed Material at any time; however, doing so 336 | will not terminate this Public License. 337 | 338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 339 | License. 340 | 341 | 342 | Section 7 -- Other Terms and Conditions. 343 | 344 | a. The Licensor shall not be bound by any additional or different 345 | terms or conditions communicated by You unless expressly agreed. 346 | 347 | b. Any arrangements, understandings, or agreements regarding the 348 | Licensed Material not stated herein are separate from and 349 | independent of the terms and conditions of this Public License. 350 | 351 | 352 | Section 8 -- Interpretation. 353 | 354 | a. For the avoidance of doubt, this Public License does not, and 355 | shall not be interpreted to, reduce, limit, restrict, or impose 356 | conditions on any use of the Licensed Material that could lawfully 357 | be made without permission under this Public License. 358 | 359 | b. To the extent possible, if any provision of this Public License is 360 | deemed unenforceable, it shall be automatically reformed to the 361 | minimum extent necessary to make it enforceable. If the provision 362 | cannot be reformed, it shall be severed from this Public License 363 | without affecting the enforceability of the remaining terms and 364 | conditions. 365 | 366 | c. No term or condition of this Public License will be waived and no 367 | failure to comply consented to unless expressly agreed to by the 368 | Licensor. 369 | 370 | d. Nothing in this Public License constitutes or may be interpreted 371 | as a limitation upon, or waiver of, any privileges and immunities 372 | that apply to the Licensor or You, including from the legal 373 | processes of any jurisdiction or authority. 374 | 375 | 376 | ======================================================================= 377 | 378 | Creative Commons is not a party to its public 379 | licenses. Notwithstanding, Creative Commons may elect to apply one of 380 | its public licenses to material it publishes and in those instances 381 | will be considered the “Licensor.” The text of the Creative Commons 382 | public licenses is dedicated to the public domain under the CC0 Public 383 | Domain Dedication. Except for the limited purpose of indicating that 384 | material is shared under a Creative Commons public license or as 385 | otherwise permitted by the Creative Commons policies published at 386 | creativecommons.org/policies, Creative Commons does not authorize the 387 | use of the trademark "Creative Commons" or any other trademark or logo 388 | of Creative Commons without its prior written consent including, 389 | without limitation, in connection with any unauthorized modifications 390 | to any of its public licenses or any other arrangements, 391 | understandings, or agreements concerning use of licensed material. For 392 | the avoidance of doubt, this paragraph does not form part of the 393 | public licenses. 394 | 395 | Creative Commons may be contacted at creativecommons.org. 396 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **IMPORTANT NOTICE:** 2 | > 3 | > As of May, 2023, all 30-seconds content repositories have been merged into [30-seconds-of-code](https://github.com/30-seconds/30-seconds-of-code). 4 | > 5 | > Please watch, star and follow relevant activity there. 6 | 7 | [![Logo](/logo.png)](https://30secondsofcode.org/css/p/1) 8 | 9 | # 30 seconds of code 10 | 11 | > Short CSS code snippets for all your development needs 12 | 13 | * Visit [our website](https://30secondsofcode.org) to view our snippet collection. 14 | * Use the [Search page](https://30secondsofcode.org/search) to find snippets that suit your needs. You can search by name, tag, language or using a snippet's description. Just start typing a term and see what comes up. 15 | * Browse the [CSS Snippet collection](https://30secondsofcode.org/css/p/1) to see all the snippets in this project or click individual tags at the top of the same page to narrow down your search to a specific tag. 16 | * Click on each snippet card to view the whole snippet, including code, explanation and examples. 17 | * You can use the button at the bottom of a snippet card to view the snippet in Codepen. 18 | * If you like the project, give it a star. It means a lot to the people maintaining it. 19 | 20 | ## Want to contribute? 21 | 22 | * If you want to help us improve, take a minute to read the [Contribution Guidelines](/CONTRIBUTING.md) first. 23 | * Use the [Snippet Template](/snippet-template.md) to add new snippets to the collection. 24 | * If you find a problem with a specific snippet, please [open an issue](https://github.com/30-seconds/30-seconds-of-css/issues/new). 25 | * If you find a problem with the website, please [report it in the web repository](https://github.com/30-seconds/30-seconds-web/issues/new). 26 | 27 | ## Credits 28 | 29 | * This repository is maintained by the [30 seconds of code organization on GitHub](https://github.com/30-seconds). 30 | * All snippets are licensed under the CC-BY-4.0 License, unless explicitly stated otherwise. 31 | * Logos, names and trademarks are not to be used without the explicit consent of the owners of the 30 seconds of code GitHub organization. 32 | * Our website is powered by [Netlify](https://www.netlify.com/), [Next.js](https://nextjs.org/) & [GitHub](https://github.com/). 33 | -------------------------------------------------------------------------------- /languageFix.css: -------------------------------------------------------------------------------- 1 | /* This file is here only to tag the repository language. Do not delete, please! */ 2 | html { 3 | margin: 0; 4 | } 5 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Chalarangelo/30-seconds-of-css/445f22efcc964bd0f2a0097cefcb12e1547c23af/logo.png -------------------------------------------------------------------------------- /snippet-template.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Snippet Name 3 | type: snippet 4 | tags: [other] 5 | cover: image 6 | dateModified: 2021-06-13T05:00:00-04:00 7 | --- 8 | 9 | Explain briefly what the snippet does. 10 | 11 | - Explain briefly how the snippet works. 12 | - Use bullet points for your snippet's explanation. 13 | - Try to explain everything briefly but clearly. 14 | 15 | ```html 16 |
17 | ``` 18 | 19 | ```css 20 | .my-snippet { 21 | background-color: #fff; 22 | border: 1px solid #000; 23 | border-radius: 4px; 24 | } 25 | ``` 26 | 27 | ```js 28 | console.log( 29 | "This is optional, if your snippet doesn't require JavaScript, be sure to delete this block!" 30 | ) 31 | ``` 32 | -------------------------------------------------------------------------------- /snippets/aspect-ratio.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Aspect ratio 3 | type: snippet 4 | tags: [layout] 5 | author: chalarangelo 6 | cover: digital-nomad-12 7 | dateModified: 2022-08-14T05:00:00-04:00 8 | --- 9 | 10 | Creates a responsive container with a specified aspect ratio. 11 | 12 | - Use a CSS custom property, `--aspect-ratio` to define the desired aspect ratio. 13 | - Set the container element to `position: relative` and `height: 0`, calculating its height using the `calc()` function and the `--aspect-ratio` custom property. 14 | - Set the direct child of the container element to `position: absolute` and filling it parent, while giving it `object-fit: cover` to maintain the aspect ratio. 15 | 16 | ```html 17 |
18 | 19 |
20 | ``` 21 | 22 | ```css 23 | .container { 24 | --aspect-ratio: 16/9; 25 | position: relative; 26 | height: 0; 27 | padding-bottom: calc(100% / (var(--aspect-ratio))); 28 | } 29 | 30 | .container > * { 31 | position: absolute; 32 | top: 0; 33 | left: 0; 34 | width: 100%; 35 | height: 100%; 36 | object-fit: cover; 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /snippets/border-with-top-triangle.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Border with top triangle 3 | type: snippet 4 | tags: [visual] 5 | cover: greek-coffee 6 | dateModified: 2021-01-07T23:52:15+02:00 7 | --- 8 | 9 | Creates a content container with a triangle at the top. 10 | 11 | - Use the `::before` and `::after` pseudo-elements to create two triangles. 12 | - The colors of the two triangles should be the same as the container's `border-color` and the container's `background-color` respectively. 13 | - The `border-width` of the one triangle (`::before`) should be `1px` wider than the other one (`::after`), in order to act as the border. 14 | - The smaller triangle (`::after`) should be `1px` to the right of the larger triangle (`::before`) to allow for its left border to be shown. 15 | 16 | ```html 17 |
Border with top triangle
18 | ``` 19 | 20 | ```css 21 | .container { 22 | position: relative; 23 | background: #ffffff; 24 | padding: 15px; 25 | border: 1px solid #dddddd; 26 | margin-top: 20px; 27 | } 28 | 29 | .container::before, 30 | .container::after { 31 | content: ''; 32 | position: absolute; 33 | bottom: 100%; 34 | left: 19px; 35 | border: 11px solid transparent; 36 | border-bottom-color: #dddddd; 37 | } 38 | 39 | .container::after { 40 | left: 20px; 41 | border: 10px solid transparent; 42 | border-bottom-color: #ffffff; 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /snippets/bouncing-loader.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Bouncing loader 3 | type: snippet 4 | tags: [animation] 5 | cover: digital-nomad-12 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Creates a bouncing loader animation. 10 | 11 | - Use `@keyframes` to define a bouncing animation, using the `opacity` and `transform` properties. Use a single axis translation on `transform: translate3d()` to achieve better animation performance. 12 | - Create a parent container, `.bouncing-loader`, for the bouncing circles. Use `display: flex` and `justify-content: center` to position them in the center. 13 | - Give the three bouncing circle `
` elements the same `width` and `height` and `border-radius: 50%` to make them circular. 14 | - Apply the `bouncing-loader` animation to each of the three bouncing circles. 15 | - Use a different `animation-delay` for each circle and `animation-direction: alternate` to create the appropriate effect. 16 | 17 | ```html 18 |
19 |
20 |
21 |
22 |
23 | ``` 24 | 25 | ```css 26 | @keyframes bouncing-loader { 27 | to { 28 | opacity: 0.1; 29 | transform: translate3d(0, -16px, 0); 30 | } 31 | } 32 | 33 | .bouncing-loader { 34 | display: flex; 35 | justify-content: center; 36 | } 37 | 38 | .bouncing-loader > div { 39 | width: 16px; 40 | height: 16px; 41 | margin: 3rem 0.2rem; 42 | background: #8385aa; 43 | border-radius: 50%; 44 | animation: bouncing-loader 0.6s infinite alternate; 45 | } 46 | 47 | .bouncing-loader > div:nth-child(2) { 48 | animation-delay: 0.2s; 49 | } 50 | 51 | .bouncing-loader > div:nth-child(3) { 52 | animation-delay: 0.4s; 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /snippets/box-sizing-reset.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Box-sizing reset 3 | type: snippet 4 | tags: [layout] 5 | cover: interior 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Resets the box-model so that `width` and `height` are not affected by `border` or `padding`. 10 | 11 | - Use `box-sizing: border-box` to include the width and height of `padding` and `border` when calculating the element's `width` and `height`. 12 | - Use `box-sizing: inherit` to pass down the `box-sizing` property from parent to child elements. 13 | 14 | ```html 15 |
border-box
16 |
content-box
17 | ``` 18 | 19 | ```css 20 | div { 21 | box-sizing: border-box; 22 | } 23 | 24 | *, 25 | *::before, 26 | *::after { 27 | box-sizing: inherit; 28 | } 29 | 30 | .box { 31 | display: inline-block; 32 | width: 120px; 33 | height: 120px; 34 | padding: 8px; 35 | margin: 8px; 36 | background: #F24333; 37 | color: white; 38 | border: 1px solid #BA1B1D; 39 | border-radius: 4px; 40 | } 41 | 42 | .content-box { 43 | box-sizing: content-box; 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /snippets/broken-image-fallback.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Fallback for images that fail to load 3 | type: snippet 4 | shortTitle: Broken image fallback 5 | tags: [visual] 6 | author: chalarangelo 7 | cover: building-facade 8 | dateModified: 2022-11-04T05:00:00-04:00 9 | --- 10 | 11 | Displays an error message when an image fails to load. 12 | 13 | - Apply styles to the `img` element as if it was a text container. 14 | - Use the `::before` and `::after` pseudo-elements to display an error message and the image URL. These elements will only be displayed if the image fails to load. 15 | 16 | ```html 17 | 18 | ``` 19 | 20 | ```css 21 | img { 22 | display: block; 23 | font-family: sans-serif; 24 | font-weight: 300; 25 | height: auto; 26 | line-height: 2; 27 | position: relative; 28 | text-align: center; 29 | width: 100%; 30 | } 31 | 32 | img::before { 33 | content: "Sorry, this image is unavailable."; 34 | display: block; 35 | margin-bottom: 8px; 36 | } 37 | 38 | img::after { 39 | content: "(url: " attr(src) ")"; 40 | display: block; 41 | font-size: 12px; 42 | } 43 | ``` 44 | -------------------------------------------------------------------------------- /snippets/button-border-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Button border animation 3 | type: snippet 4 | tags: [animation] 5 | cover: highlands 6 | dateModified: 2021-05-24T15:28:52+03:00 7 | --- 8 | 9 | Creates a border animation on hover. 10 | 11 | - Use the `::before` and `::after` pseudo-elements to create two boxes `24px` wide opposite each other above and below the box. 12 | - Use the `:hover` pseudo-class to extend the `width` of those elements to `100%` on hover and animate the change using `transition`. 13 | 14 | ```html 15 | 16 | ``` 17 | 18 | ```css 19 | .animated-border-button { 20 | background-color: #263059; 21 | border: none; 22 | color: #ffffff; 23 | outline: none; 24 | padding: 12px 40px 10px; 25 | position: relative; 26 | } 27 | 28 | .animated-border-button::before, 29 | .animated-border-button::after { 30 | border: 0 solid transparent; 31 | transition: all 0.3s; 32 | content: ''; 33 | height: 0; 34 | position: absolute; 35 | width: 24px; 36 | } 37 | 38 | .animated-border-button::before { 39 | border-top: 2px solid #263059; 40 | right: 0; 41 | top: -4px; 42 | } 43 | 44 | .animated-border-button::after { 45 | border-bottom: 2px solid #263059; 46 | bottom: -4px; 47 | left: 0; 48 | } 49 | 50 | .animated-border-button:hover::before, 51 | .animated-border-button:hover::after { 52 | width: 100%; 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /snippets/button-focus-swing-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Button swing animation 3 | type: snippet 4 | tags: [animation] 5 | author: chalarangelo 6 | cover: painters-desk 7 | dateModified: 2021-05-24T15:28:52+03:00 8 | --- 9 | 10 | Creates a swing animation on focus. 11 | 12 | - Use an appropriate `transition` to animate changes to the element. 13 | - Use the `:focus` pseudo-class to apply an `animation` that uses `transform` to make the element swing. 14 | - Use `animation-iteration-count` to only play the animation once. 15 | 16 | ```html 17 | 18 | ``` 19 | 20 | ```css 21 | .button-swing { 22 | color: #65b5f6; 23 | background-color: transparent; 24 | border: 1px solid #65b5f6; 25 | border-radius: 4px; 26 | padding: 0 16px; 27 | cursor: pointer; 28 | transition: all 0.2s ease-in-out; 29 | } 30 | 31 | .button-swing:focus { 32 | animation: swing 1s ease; 33 | animation-iteration-count: 1; 34 | } 35 | 36 | @keyframes swing { 37 | 15% { 38 | transform: translateX(5px); 39 | } 40 | 30% { 41 | transform: translateX(-5px); 42 | } 43 | 50% { 44 | transform: translateX(3px); 45 | } 46 | 65% { 47 | transform: translateX(-3px); 48 | } 49 | 80% { 50 | transform: translateX(2px); 51 | } 52 | 100% { 53 | transform: translateX(0); 54 | } 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /snippets/button-hover-fill-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Button fill animation 3 | type: snippet 4 | tags: [animation] 5 | cover: beach-pineapple 6 | dateModified: 2021-04-02T21:34:43+03:00 7 | --- 8 | 9 | Creates a fill animation on hover. 10 | 11 | - Set a `color` and `background` and use an appropriate `transition` to animate changes to the element. 12 | - Use the `:hover` pseudo-class to change the `background` and `color` of the element when the user hovers over it. 13 | 14 | ```html 15 | 16 | ``` 17 | 18 | ```css 19 | .animated-fill-button { 20 | padding: 20px; 21 | background: #fff; 22 | color: #000; 23 | border: 1px solid #000; 24 | cursor: pointer; 25 | transition: 0.3s all ease-in-out; 26 | } 27 | 28 | .animated-fill-button:hover { 29 | background: #000; 30 | color: #fff; 31 | } 32 | ``` 33 | -------------------------------------------------------------------------------- /snippets/button-hover-grow-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Button grow animation 3 | type: snippet 4 | tags: [animation] 5 | author: chalarangelo 6 | cover: white-laptop 7 | dateModified: 2021-05-24T15:28:52+03:00 8 | --- 9 | 10 | Creates a grow animation on hover. 11 | 12 | - Use an appropriate `transition` to animate changes to the element. 13 | - Use the `:hover` pseudo-class to change the `transform` to `scale(1.1)`, growing the element when the user hovers over it. 14 | 15 | ```html 16 | 17 | ``` 18 | 19 | ```css 20 | .button-grow { 21 | color: #65b5f6; 22 | background-color: transparent; 23 | border: 1px solid #65b5f6; 24 | border-radius: 4px; 25 | padding: 0 16px; 26 | cursor: pointer; 27 | transition: all 0.3s ease-in-out; 28 | } 29 | 30 | .button-grow:hover { 31 | transform: scale(1.1); 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /snippets/button-hover-shrink-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Button shrink animation 3 | type: snippet 4 | tags: [animation] 5 | author: chalarangelo 6 | cover: clay-pot-horizon 7 | dateModified: 2021-05-24T15:28:52+03:00 8 | --- 9 | 10 | Creates a shrink animation on hover. 11 | 12 | - Use an appropriate `transition` to animate changes to the element. 13 | - Use the `:hover` pseudo-class to change the `transform` to `scale(0.8)`, shrinking the element when the user hovers over it. 14 | 15 | ```html 16 | 17 | ``` 18 | 19 | ```css 20 | .button-shrink { 21 | color: #65b5f6; 22 | background-color: transparent; 23 | border: 1px solid #65b5f6; 24 | border-radius: 4px; 25 | padding: 0 16px; 26 | cursor: pointer; 27 | transition: all 0.3s ease-in-out; 28 | } 29 | 30 | .button-shrink:hover { 31 | transform: scale(0.8); 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /snippets/card-image-cutout.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Card with image cutout 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: radio-monstera 7 | dateModified: 2022-12-11T05:00:00-04:00 8 | --- 9 | 10 | Creates a card with an image cutout. 11 | 12 | - Use `background` to add a colored background to a `.container` element. 13 | - Create a `.card` containing a `figure` with the appropriate image for the cutout and any other content you want. 14 | - Use the `::before` pseudo-element to add a `border` around the `figure` element, matching the `.container` element's `background` and creating the illusion of a cutout in the `.card`. 15 | 16 | ```html 17 |
18 |
19 |
20 | 21 |
22 |

Lorem ipsum dolor sit amet consectetur adipisicing elit.

23 |
24 |
25 | ``` 26 | 27 | ```css 28 | .container { 29 | display: flex; 30 | padding: 96px 24px 48px; 31 | justify-content: center; 32 | align-items: center; 33 | background: #f3f1fe; 34 | } 35 | 36 | .card { 37 | width: 350px; 38 | display: flex; 39 | flex-direction: column; 40 | align-items: center; 41 | background: #fff; 42 | border-radius: 10px; 43 | margin: 8px; 44 | box-shadow: 0 0 5px -2px rgba(0, 0, 0, 0.1); 45 | } 46 | 47 | .card figure { 48 | width: 120px; 49 | height: 120px; 50 | border-radius: 50%; 51 | margin-top: -60px; 52 | position: relative; 53 | } 54 | 55 | .card figure::before { 56 | content: ""; 57 | border-radius: inherit; 58 | position: absolute; 59 | top: 50%; 60 | left: 50%; 61 | width: 100%; 62 | height: 100%; 63 | transform: translate(-50%, -50%); 64 | border: 1rem solid #f3f1fe; 65 | box-shadow: 0 1px rgba(0, 0, 0, 0.1); 66 | } 67 | 68 | .card figure img { 69 | border-radius: inherit; 70 | width: 100%; 71 | height: 100%; 72 | object-fit: cover; 73 | } 74 | 75 | .card .content { 76 | text-align: center; 77 | margin: 2rem; 78 | line-height: 1.5; 79 | color: #101010; 80 | } 81 | ``` 82 | -------------------------------------------------------------------------------- /snippets/checkerboard-pattern.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Checkerboard background pattern 3 | type: snippet 4 | tags: [visual] 5 | cover: digital-nomad-2 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates a checkerboard background pattern. 10 | 11 | - Use `background-color` to set a white background. 12 | - Use `background-image` with two `linear-gradient()` values. Give each one a different angle to create the checkerboard pattern. 13 | - Use `background-size` to specify the pattern's size. 14 | - **Note:** The fixed `height` and `width` of the element is for demonstration purposes only. 15 | 16 | ```html 17 |
18 | ``` 19 | 20 | ```css 21 | .checkerboard { 22 | width: 240px; 23 | height: 240px; 24 | background-color: #fff; 25 | background-image: linear-gradient( 26 | 45deg, 27 | #000 25%, 28 | transparent 25%, 29 | transparent 75%, 30 | #000 75%, 31 | #000 32 | ), 33 | linear-gradient( 34 | -45deg, 35 | #000 25%, 36 | transparent 25%, 37 | transparent 75%, 38 | #000 75%, 39 | #000 40 | ); 41 | background-size: 60px 60px; 42 | background-repeat: repeat; 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /snippets/circle.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Circle 3 | type: snippet 4 | tags: [visual] 5 | cover: oven-paddle 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Creates a circular shape with pure CSS. 10 | 11 | - Use `border-radius: 50%` to curve the borders of the element to create a circle. 12 | - 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. 13 | 14 | ```html 15 |
16 | ``` 17 | 18 | ```css 19 | .circle { 20 | border-radius: 50%; 21 | width: 32px; 22 | height: 32px; 23 | background: #9C27B0; 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /snippets/clearfix.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Clearfix 3 | type: snippet 4 | tags: [layout] 5 | cover: memories-of-pineapple-3 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Ensures that an element self-clears its children. 10 | 11 | - Use the `::after` pseudo-element and apply `content: ''` to allow it to affect layout. 12 | - Use `clear: both` to make the element clear past both left and right floats. 13 | - For this technique to work properly, make sure 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). 14 | - **Note:** This is only useful if you are using `float` to build layouts. Consider using a more modern approach, such as the flexbox or grid layout. 15 | 16 | ```html 17 |
18 |
float a
19 |
float b
20 |
float c
21 |
22 | ``` 23 | 24 | ```css 25 | .clearfix::after { 26 | content: ''; 27 | display: block; 28 | clear: both; 29 | } 30 | 31 | .floated { 32 | float: left; 33 | padding: 4px; 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /snippets/constant-width-to-height-ratio.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Constant width to height ratio 3 | type: snippet 4 | tags: [layout] 5 | cover: clutter 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Ensures that an element with variable `width` will retain a proportionate `height` value. 10 | 11 | - Apply `padding-top` on the `::before` pseudo-element, making the `height` of the element equal to a percentage of its `width`. 12 | - The proportion of `height` to `width` can be altered as necessary. For example a `padding-top` of `100%` will create a responsive square (1:1 ratio). 13 | 14 | ```html 15 |
16 | ``` 17 | 18 | ```css 19 | .constant-width-to-height-ratio { 20 | background: #9C27B0; 21 | width: 50%; 22 | } 23 | 24 | .constant-width-to-height-ratio::before { 25 | content: ''; 26 | padding-top: 100%; 27 | float: left; 28 | } 29 | 30 | .constant-width-to-height-ratio::after { 31 | content: ''; 32 | display: block; 33 | clear: both; 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /snippets/counter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Counter 3 | type: snippet 4 | tags: [visual] 5 | cover: laptop-plants 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Creates a custom list counter that accounts for nested list elements. 10 | 11 | - Use `counter-reset` to initialize a variable counter (default `0`), the name of which is the value of the attribute (i.e. `counter`). 12 | - Use `counter-increment` on the variable counter for each countable element (i.e. each `
  • `). 13 | - Use `counters()` to display the value of each variable counter as part of the `content` of the `::before` pseudo-element for each countable element (i.e. each `
  • `). The second value passed to it (`'.'`) acts as the delimiter for nested counters. 14 | 15 | ```html 16 | 28 | ``` 29 | 30 | ```css 31 | ul { 32 | counter-reset: counter; 33 | list-style: none; 34 | } 35 | 36 | li::before { 37 | counter-increment: counter; 38 | content: counters(counter, '.') ' '; 39 | } 40 | ``` 41 | -------------------------------------------------------------------------------- /snippets/custom-checkbox.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Custom checkbox 3 | type: snippet 4 | tags: [visual,animation] 5 | author: chalarangelo 6 | cover: interior-8 7 | dateModified: 2021-10-11T18:44:51+03:00 8 | --- 9 | 10 | Creates a styled checkbox with animation on state change. 11 | 12 | - Use an `` element to create the check `` and insert it via the `` element to create a reusable SVG icon. 13 | - Create a `.checkbox-container` and use flexbox to create the appropriate layout for the checkboxes. 14 | - Hide the `
    31 | 32 | 40 | 41 | 49 |
    50 | ``` 51 | 52 | ```css 53 | .checkbox-symbol { 54 | position: absolute; 55 | width: 0; 56 | height: 0; 57 | pointer-events: none; 58 | user-select: none; 59 | } 60 | 61 | .checkbox-container { 62 | box-sizing: border-box; 63 | background: #ffffff; 64 | color: #222; 65 | height: 64px; 66 | display: flex; 67 | justify-content: center; 68 | align-items: center; 69 | flex-flow: row wrap; 70 | } 71 | 72 | .checkbox-container * { 73 | box-sizing: border-box; 74 | } 75 | 76 | .checkbox-input { 77 | position: absolute; 78 | visibility: hidden; 79 | } 80 | 81 | .checkbox { 82 | user-select: none; 83 | cursor: pointer; 84 | padding: 6px 8px; 85 | border-radius: 6px; 86 | overflow: hidden; 87 | transition: all 0.3s ease; 88 | display: flex; 89 | } 90 | 91 | .checkbox:not(:last-child) { 92 | margin-right: 6px; 93 | } 94 | 95 | .checkbox:hover { 96 | background: rgba(0, 119, 255, 0.06); 97 | } 98 | 99 | .checkbox span { 100 | vertical-align: middle; 101 | transform: translate3d(0, 0, 0); 102 | } 103 | 104 | .checkbox span:first-child { 105 | position: relative; 106 | flex: 0 0 18px; 107 | width: 18px; 108 | height: 18px; 109 | border-radius: 4px; 110 | transform: scale(1); 111 | border: 1px solid #cccfdb; 112 | transition: all 0.3s ease; 113 | } 114 | 115 | .checkbox span:first-child svg { 116 | position: absolute; 117 | top: 3px; 118 | left: 2px; 119 | fill: none; 120 | stroke: #fff; 121 | stroke-dasharray: 16px; 122 | stroke-dashoffset: 16px; 123 | transition: all 0.3s ease; 124 | transform: translate3d(0, 0, 0); 125 | } 126 | 127 | .checkbox span:last-child { 128 | padding-left: 8px; 129 | line-height: 18px; 130 | } 131 | 132 | .checkbox:hover span:first-child { 133 | border-color: #0077ff; 134 | } 135 | 136 | .checkbox-input:checked + .checkbox span:first-child { 137 | background: #0077ff; 138 | border-color: #0077ff; 139 | animation: zoom-in-out 0.3s ease; 140 | } 141 | 142 | .checkbox-input:checked + .checkbox span:first-child svg { 143 | stroke-dashoffset: 0; 144 | } 145 | 146 | @keyframes zoom-in-out { 147 | 50% { 148 | transform: scale(0.9); 149 | } 150 | } 151 | ``` 152 | -------------------------------------------------------------------------------- /snippets/custom-radio.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Custom radio button 3 | type: snippet 4 | tags: [visual,animation] 5 | author: chalarangelo 6 | cover: messy-computer 7 | dateModified: 2022-11-16T05:00:00-04:00 8 | --- 9 | 10 | Creates a styled radio button with animation on state change. 11 | 12 | - Create a `.radio-container` and use flexbox to create the appropriate layout for the radio buttons. 13 | - Reset the styles on the `` and use it to create the outline and background of the radio button. 14 | - Use the `::before` element to create the inner circle of the radio button. 15 | - Use `transform: scale(1)` and a CSS transition to create an animation effect on state change. 16 | 17 | ```html 18 |
    19 | 20 | 21 | 22 | 23 |
    24 | ``` 25 | 26 | ```css 27 | .radio-container { 28 | box-sizing: border-box; 29 | background: #ffffff; 30 | color: #222; 31 | height: 64px; 32 | display: flex; 33 | justify-content: center; 34 | align-items: center; 35 | flex-flow: row wrap; 36 | } 37 | 38 | .radio-container * { 39 | box-sizing: border-box; 40 | } 41 | 42 | .radio-input { 43 | appearance: none; 44 | background-color: #ffffff; 45 | width: 16px; 46 | height: 16px; 47 | border: 1px solid #cccfdb; 48 | margin: 0; 49 | border-radius: 50%; 50 | display: grid; 51 | align-items: center; 52 | justify-content: center; 53 | transition: all 0.3s ease; 54 | } 55 | 56 | .radio-input::before { 57 | content: ""; 58 | width: 6px; 59 | height: 6px; 60 | border-radius: 50%; 61 | transform: scale(0); 62 | transition: 0.3s transform ease-in-out; 63 | box-shadow: inset 6px 6px #ffffff; 64 | } 65 | 66 | .radio-input:checked { 67 | background: #0077ff; 68 | border-color: #0077ff; 69 | } 70 | 71 | .radio-input:checked::before { 72 | transform: scale(1); 73 | } 74 | 75 | .radio { 76 | cursor: pointer; 77 | padding: 6px 8px; 78 | } 79 | 80 | .radio:not(:last-child) { 81 | margin-right: 6px; 82 | } 83 | ``` 84 | -------------------------------------------------------------------------------- /snippets/custom-scrollbar.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Custom scrollbar 3 | type: snippet 4 | tags: [visual] 5 | cover: sea-view 6 | dateModified: 2021-05-16T13:09:15+03:00 7 | --- 8 | 9 | Customizes the scrollbar style for elements with scrollable overflow. 10 | 11 | - Use `::-webkit-scrollbar` to style the scrollbar element. 12 | - Use `::-webkit-scrollbar-track` to style the scrollbar track (the background of the scrollbar). 13 | - Use `::-webkit-scrollbar-thumb` to style the scrollbar thumb (the draggable element). 14 | - **Note:** Scrollbar styling doesn't appear to be on any standards track. This technique only works on WebKit-based browsers. 15 | 16 | ```html 17 |
    18 |

    19 | Lorem ipsum dolor sit amet consectetur adipisicing elit.
    20 | Iure id exercitationem nulla qui repellat laborum vitae,
    21 | molestias tempora velit natus. Quas, assumenda nisi.
    22 | Quisquam enim qui iure, consequatur velit sit? 23 |

    24 |
    25 | ``` 26 | 27 | ```css 28 | .custom-scrollbar { 29 | height: 70px; 30 | overflow-y: scroll; 31 | } 32 | 33 | .custom-scrollbar::-webkit-scrollbar { 34 | width: 8px; 35 | } 36 | 37 | .custom-scrollbar::-webkit-scrollbar-track { 38 | background: #1E3F20; 39 | border-radius: 12px; 40 | } 41 | 42 | .custom-scrollbar::-webkit-scrollbar-thumb { 43 | background: #4A7856; 44 | border-radius: 12px; 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /snippets/custom-text-selection.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Custom text selection 3 | type: snippet 4 | tags: [visual] 5 | cover: digital-nomad 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Changes the styling of text selection. 10 | 11 | - Use the `::selection` pseudo-selector to style text within it when selected. 12 | 13 | ```html 14 |

    Select some of this text.

    15 | ``` 16 | 17 | ```css 18 | ::selection { 19 | background: aquamarine; 20 | color: black; 21 | } 22 | 23 | .custom-text-selection::selection { 24 | background: deeppink; 25 | color: white; 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /snippets/disable-selection.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Disable selection 3 | type: snippet 4 | tags: [interactivity] 5 | cover: interior-9 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Makes the content unselectable. 10 | 11 | - Use `user-select: none` to make the content of the element not selectable. 12 | - **Note:** This is not a secure method to prevent users from copying content. 13 | 14 | ```html 15 |

    You can select me.

    16 |

    You can't select me!

    17 | ``` 18 | 19 | ```css 20 | .unselectable { 21 | user-select: none; 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /snippets/display-empty-links.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Style links with no text 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: metro-tunnel 7 | dateModified: 2022-11-11T05:00:00-04:00 8 | --- 9 | 10 | Displays the link URL for links with no text. 11 | 12 | - Use the `:empty` pseudo-class to select links with no text. 13 | - Use the `:not` pseudo-class to exclude links with text. 14 | - Use the `content` property and the `attr()` function to display the link URL in the `::before` pseudo-element. 15 | 16 | ```html 17 | 18 | ``` 19 | 20 | ```css 21 | a[href^="http"]:empty::before { 22 | content: attr(href); 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /snippets/display-table-centering.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Display table centering 3 | type: snippet 4 | tags: [layout] 5 | cover: malibu 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Vertically and horizontally centers a child element within its parent element, using `display: table`. 10 | 11 | - Use `display: table` to make the `.center` element behave like a `` element. 12 | - Set `height` and `width` to `100%` to make the element fill the available space within its parent element. 13 | - Use `display: table-cell` on the child element to make it behave like a ``, `

    `, `

      `, etc. 13 | 14 | ```html 15 |
        16 |
      • Item 01
      • 17 |
      • Item 02
      • 18 |
      • Item 03
      • 19 |
      • Item 04
      • 20 |
      • Item 05
      • 21 |
      22 | ``` 23 | 24 | ```css 25 | li:nth-child(odd) { 26 | background-color: #999; 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /snippets/zig-zag-pattern.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Zig zag background pattern 3 | type: snippet 4 | tags: [visual] 5 | cover: blue-lake 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates a zig zag background pattern. 10 | 11 | - Use `background-color` to set a white background. 12 | - Use `background-image` with four `linear-gradient()` values to create the parts of a zig zag pattern. 13 | - Use `background-size` to specify the pattern's size. Use `background-position` to place the parts of the pattern in the correct locations. 14 | - **Note:** The fixed `height` and `width` of the element is for demonstration purposes only. 15 | 16 | ```html 17 |
      18 | ``` 19 | 20 | ```css 21 | .zig-zag { 22 | width: 240px; 23 | height: 240px; 24 | background-color: #fff; 25 | background-image: linear-gradient(135deg, #000 25%, transparent 25%), 26 | linear-gradient(225deg, #000 25%, transparent 25%), 27 | linear-gradient(315deg, #000 25%, transparent 25%), 28 | linear-gradient(45deg, #000 25%, transparent 25%); 29 | background-position: -30px 0, -30px 0, 0 0, 0 0; 30 | background-size: 60px 60px; 31 | background-repeat: repeat; 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /snippets/zoomin-zoomout-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Zoom in zoom out animation 3 | type: snippet 4 | tags: [animation] 5 | cover: travel-mug-2 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates a zoom in zoom out animation. 10 | 11 | - Use `@keyframes` to define a three-step animation. At the start (`0%`) and end (`100%`), the element is its original size (`scale(1 ,1)`). Halfway through (`50%`) it's scaled up to 1.5 times its original size (`scale(1.5, 1.5)`). 12 | - Use `width` and `height` to give the element a specific size. 13 | - Use `animation` to set the appropriate values for the element to make it animated. 14 | 15 | ```html 16 |
      17 | ``` 18 | 19 | ```css 20 | .zoom-in-out-box { 21 | margin: 24px; 22 | width: 50px; 23 | height: 50px; 24 | background: #f50057; 25 | animation: zoom-in-zoom-out 1s ease infinite; 26 | } 27 | 28 | @keyframes zoom-in-zoom-out { 29 | 0% { 30 | transform: scale(1, 1); 31 | } 32 | 50% { 33 | transform: scale(1.5, 1.5); 34 | } 35 | 100% { 36 | transform: scale(1, 1); 37 | } 38 | } 39 | ``` 40 | --------------------------------------------------------------------------------
    ` elements. 14 | - Use `text-align: center` and `vertical-align: middle` on the child element to center it horizontally and vertically. 15 | - The outer parent (`.container`) must have a fixed `width` and `height`. 16 | 17 | ```html 18 |
    19 |
    Centered content
    20 |
    21 | ``` 22 | 23 | ```css 24 | .container { 25 | border: 1px solid #9C27B0; 26 | height: 250px; 27 | width: 250px; 28 | } 29 | 30 | .center { 31 | display: table; 32 | height: 100%; 33 | width: 100%; 34 | } 35 | 36 | .center > span { 37 | display: table-cell; 38 | text-align: center; 39 | vertical-align: middle; 40 | } 41 | ``` 42 | -------------------------------------------------------------------------------- /snippets/donut-spinner.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Donut spinner 3 | type: snippet 4 | tags: [animation] 5 | cover: digital-nomad-3 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates a donut spinner that can be used to indicate the loading of content. 10 | 11 | - Use a semi-transparent `border` for the whole element. Exclude one side that will serve as the loading indicator for the donut. 12 | - Define and use an appropriate animation, using `transform: rotate()` to rotate the element. 13 | 14 | ```html 15 |
    16 | ``` 17 | 18 | ```css 19 | @keyframes donut-spin { 20 | 0% { 21 | transform: rotate(0deg); 22 | } 23 | 100% { 24 | transform: rotate(360deg); 25 | } 26 | } 27 | 28 | .donut { 29 | display: inline-block; 30 | border: 4px solid rgba(0, 0, 0, 0.1); 31 | border-left-color: #7983ff; 32 | border-radius: 50%; 33 | width: 30px; 34 | height: 30px; 35 | animation: donut-spin 1.2s linear infinite; 36 | } 37 | ``` 38 | -------------------------------------------------------------------------------- /snippets/drop-cap.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Drop cap 3 | type: snippet 4 | tags: [visual] 5 | cover: bamboo-lamp 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Makes the first letter of the first paragraph bigger than the rest of the text. 10 | 11 | - Use the `:first-child` selector to select only the first paragraph. 12 | - Use the `::first-letter` pseudo-element to style the first element of the paragraph. 13 | 14 | ```html 15 |

    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.

    16 |

    Donec magna erat, imperdiet non odio sed, sodales tempus magna. Integer vitae orci lectus. Nullam consectetur orci at pellentesque efficitur.

    17 | ``` 18 | 19 | ```css 20 | p:first-child::first-letter { 21 | color: #5f79ff; 22 | float: left; 23 | margin: 0 8px 0 4px; 24 | font-size: 3rem; 25 | font-weight: bold; 26 | line-height: 1; 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /snippets/dynamic-shadow.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Dynamic shadow 3 | type: snippet 4 | tags: [visual] 5 | cover: couch-laptop 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Creates a shadow similar to `box-shadow` but based on the colors of the element itself. 10 | 11 | - Use the `::after` pseudo-element with `position: absolute` and `width` and `height` equal to `100%` to fill the available space in the parent element. 12 | - Use `background: inherit` to inherit the `background` of the parent element. 13 | - Use `top` to slightly offset the pseudo-element, `filter: blur()` to create a shadow and `opacity` to make it semi-transparent. 14 | - Use `z-index: 1` on the parent and `z-index: -1` on the pseudo-element to position it behind its parent. 15 | 16 | ```html 17 |
    18 | ``` 19 | 20 | ```css 21 | .dynamic-shadow { 22 | position: relative; 23 | width: 10rem; 24 | height: 10rem; 25 | background: linear-gradient(75deg, #6d78ff, #00ffb8); 26 | z-index: 1; 27 | } 28 | 29 | .dynamic-shadow::after { 30 | content: ''; 31 | width: 100%; 32 | height: 100%; 33 | position: absolute; 34 | background: inherit; 35 | top: 0.5rem; 36 | filter: blur(0.4rem); 37 | opacity: 0.7; 38 | z-index: -1; 39 | } 40 | ``` 41 | -------------------------------------------------------------------------------- /snippets/etched-text.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Etched text 3 | type: snippet 4 | tags: [visual] 5 | cover: memories-of-pineapple-2 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Creates an effect where text appears to be "etched" or engraved into the background. 10 | 11 | - Use `text-shadow` to create a white shadow offset `0px` horizontally and `2px` vertically from the origin position. 12 | - The background must be darker than the shadow for the effect to work. 13 | - The text color should be slightly faded to make it look like it's engraved/carved out of the background. 14 | 15 | ```html 16 |

    I appear etched into the background.

    17 | ``` 18 | 19 | ```css 20 | .etched-text { 21 | text-shadow: 0 2px white; 22 | font-size: 1.5rem; 23 | font-weight: bold; 24 | color: #b8bec5; 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /snippets/evenly-distributed-children.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Evenly distributed children 3 | type: snippet 4 | tags: [layout] 5 | cover: little-bird 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Evenly distributes child elements within a parent element. 10 | 11 | - Use `display: flex` to use the flexbox layout. 12 | - Use `justify-content: space-between` to evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge. 13 | - Alternatively, use `justify-content: space-around` to distribute the children with space around them, instead of between them. 14 | 15 | ```html 16 |
    17 |

    Item1

    18 |

    Item2

    19 |

    Item3

    20 |
    21 | ``` 22 | 23 | ```css 24 | .evenly-distributed-children { 25 | display: flex; 26 | justify-content: space-between; 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /snippets/fit-image-in-container.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Fit image in container 3 | type: snippet 4 | tags: [layout,visual] 5 | cover: succulent-3 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Fits an positions an image appropriately inside its container while preserving its aspect ratio. 10 | 11 | - Use `object-fit: contain` to fit the entire image within the container while preserving its aspect ratio. 12 | - Use `object-fit: cover` to fill the container with the image while preserving its aspect ratio. 13 | - Use `object-position: center` to position the image at the center of the container. 14 | 15 | ```html 16 | 17 | 18 | ``` 19 | 20 | ```css 21 | .image { 22 | background: #34495e; 23 | border: 1px solid #34495e; 24 | width: 200px; 25 | height: 200px; 26 | } 27 | 28 | .image-contain { 29 | object-fit: contain; 30 | object-position: center; 31 | } 32 | 33 | .image-cover { 34 | object-fit: cover; 35 | object-position: right top; 36 | } 37 | ``` 38 | -------------------------------------------------------------------------------- /snippets/flexbox-centering.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Flexbox centering 3 | type: snippet 4 | tags: [layout] 5 | cover: basket-paper 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Horizontally and vertically centers a child element within a parent element using flexbox. 10 | 11 | - Use `display: flex` to create a flexbox layout. 12 | - Use `justify-content: center` to center the child horizontally. 13 | - Use `align-items: center` to center the child vertically. 14 | 15 | ```html 16 |
    17 |
    Centered content.
    18 |
    19 | ``` 20 | 21 | ```css 22 | .flexbox-centering { 23 | display: flex; 24 | justify-content: center; 25 | align-items: center; 26 | height: 100px; 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /snippets/floating-list-titles.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: List with floating section headings 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: pop-of-green 7 | dateModified: 2021-10-11T18:44:51+03:00 8 | --- 9 | 10 | Creates a list with floating headings for each section. 11 | 12 | - Use `overflow-y: auto` to allow the list container to overflow vertically. 13 | - Use `display: grid` on the inner container (`
    `) to create a layout with two columns. 14 | - Set headings (`
    `) to `grid-column: 1` and content (`
    `) to `grid-column: 2`. 15 | - Finally, apply `position: sticky` and `top: 0.5rem` to headings to create a floating effect. 16 | 17 | ```html 18 |
    19 |
    20 |
    21 |
    A
    22 |
    Algeria
    23 |
    Angola
    24 | 25 |
    B
    26 |
    Benin
    27 |
    Botswana
    28 |
    Burkina Faso
    29 |
    Burundi
    30 | 31 |
    C
    32 |
    Cabo Verde
    33 |
    Cameroon
    34 |
    Central African Republic
    35 |
    Chad
    36 |
    Comoros
    37 |
    Congo, Democratic Republic of the
    38 |
    Congo, Republic of the
    39 |
    Cote d'Ivoire
    40 | 41 |
    D
    42 |
    Djibouti
    43 | 44 |
    E
    45 |
    Egypt
    46 |
    Equatorial Guinea
    47 |
    Eritrea
    48 |
    Eswatini (formerly Swaziland)
    49 |
    Ethiopia
    50 |
    51 |
    52 |
    53 | ``` 54 | 55 | ```css 56 | .container { 57 | display: grid; 58 | place-items: center; 59 | min-height: 400px; 60 | } 61 | 62 | .floating-stack { 63 | background: #455A64; 64 | color: #fff; 65 | height: 80vh; 66 | width: 320px; 67 | border-radius: 1rem; 68 | overflow-y: auto; 69 | } 70 | 71 | .floating-stack > dl { 72 | margin: 0 0 1rem; 73 | display: grid; 74 | grid-template-columns: 2.5rem 1fr; 75 | align-items: center; 76 | } 77 | 78 | .floating-stack dt { 79 | position: sticky; 80 | top: 0.5rem; 81 | left: 0.5rem; 82 | font-weight: bold; 83 | background: #263238; 84 | color: #cfd8dc; 85 | height: 2rem; 86 | width: 2rem; 87 | border-radius: 50%; 88 | padding: 0.25rem 1rem; 89 | grid-column: 1; 90 | display: inline-flex; 91 | align-items: center; 92 | justify-content: center; 93 | box-sizing: border-box; 94 | } 95 | 96 | .floating-stack dd { 97 | grid-column: 2; 98 | margin: 0; 99 | padding: 0.75rem; 100 | } 101 | 102 | .floating-stack > dl:first-of-type > dd:first-of-type { 103 | margin-top: 0.25rem; 104 | } 105 | ``` 106 | -------------------------------------------------------------------------------- /snippets/fluid-typography.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Fluid typography 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: shell-focus 7 | dateModified: 2021-05-16T11:23:05+03:00 8 | --- 9 | 10 | Creates text that scales according to the viewport width. 11 | 12 | - Use the `clamp()` CSS function to clamp the value of `font-size` between `1rem` and `3rem`. 13 | - Use the formula `8vw - 2rem` to calculate a responsive value for `font-size` (`1rem` at `600px`, `3rem` at `1000px`). 14 | 15 | ```html 16 |

    Hello World!

    17 | ``` 18 | 19 | ```css 20 | .fluid-type { 21 | font-size: clamp(1rem, 8vw - 2rem, 3rem); 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /snippets/focus-within.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Focus Within 3 | type: snippet 4 | tags: [visual,interactivity] 5 | cover: boats 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Changes the appearance of a form if any of its children are focused. 10 | 11 | - Use the pseudo-class `:focus-within` to apply styles to a parent element if any child element gets focused. 12 | 13 | ```html 14 |
    15 | 16 | 17 |
    18 | 19 | 20 |
    21 | ``` 22 | 23 | ```css 24 | form { 25 | border: 2px solid #52B882; 26 | padding: 8px; 27 | border-radius: 2px; 28 | } 29 | 30 | form:focus-within { 31 | background: #7CF0BD; 32 | } 33 | 34 | label { 35 | display: inline-block; 36 | width: 72px; 37 | } 38 | 39 | input { 40 | margin: 4px 12px; 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /snippets/full-width.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Full-width image 3 | type: snippet 4 | tags: [layout] 5 | author: chalarangelo 6 | cover: yellow-white-mug-2 7 | dateModified: 2021-01-07T10:14:46+02:00 8 | --- 9 | 10 | Creates a full-width image. 11 | 12 | - Use `left: 50%` and `right: 50%` to position the image in the middle of the parent element. 13 | - Use `margin-left: -50vw` and `margin-right: -50vw` to offset the image on both sides relative to the size of the viewport. 14 | - Use `width: 100vw` and `max-width: 100vw` to size the image relative to the viewport. 15 | 16 | ```html 17 |
    18 |

    Lorem ipsum dolor sit amet

    19 |

    20 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris molestie 21 | lobortis sapien, sit amet iaculis est interdum tincidunt. Nunc egestas nibh 22 | ut metus elementum consequat. Integer elit orci, rhoncus efficitur lectus 23 | eu, faucibus interdum felis. 24 |

    25 |

    26 | 27 |

    28 |

    29 | Orci varius natoque penatibus et magnis dis parturient montes, nascetur 30 | ridiculus mus. Nullam pretium lectus sed ex efficitur, ac varius sapien 31 | gravida. Sed facilisis elit quis sem sollicitudin, ut aliquam neque 32 | eleifend. Maecenas sagittis neque sapien, ac tempus nulla tempus nec. 33 | Curabitur tellus est, convallis id dolor ut, porta hendrerit quam. 34 |

    35 |
    36 | ``` 37 | 38 | ```css 39 | main { 40 | margin: 0 auto; 41 | max-width: 640px; 42 | } 43 | 44 | img { 45 | height: auto; 46 | max-width: 100%; 47 | } 48 | 49 | .full-width { 50 | position: relative; 51 | left: 50%; 52 | right: 50%; 53 | margin-left: -50vw; 54 | margin-right: -50vw; 55 | max-width: 100vw; 56 | width: 100vw; 57 | } 58 | ``` 59 | -------------------------------------------------------------------------------- /snippets/fullscreen.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Fullscreen 3 | type: snippet 4 | tags: [visual] 5 | cover: flower-portrait-3 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Applies styles to an element when in fullscreen mode. 10 | 11 | - Use the `:fullscreen` CSS pseudo-element selector to select and style an element that is displayed in fullscreen mode. 12 | - Use a ` 22 | 23 | ``` 24 | 25 | ```css 26 | .container { 27 | margin: 40px auto; 28 | max-width: 700px; 29 | } 30 | 31 | .element { 32 | padding: 20px; 33 | height: 300px; 34 | width: 100%; 35 | background-color: skyblue; 36 | box-sizing: border-box; 37 | } 38 | 39 | .element p { 40 | text-align: center; 41 | color: white; 42 | font-size: 3em; 43 | } 44 | 45 | .element:-ms-fullscreen p { 46 | visibility: visible; 47 | } 48 | 49 | .element:fullscreen { 50 | background-color: #e4708a; 51 | width: 100vw; 52 | height: 100vh; 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /snippets/gradient-text.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Gradient text 3 | type: snippet 4 | tags: [visual] 5 | cover: red-berries 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Gives text a gradient color. 10 | 11 | - Use `background` with a `linear-gradient()` value to give the text element a gradient background. 12 | - Use `webkit-text-fill-color: transparent` to fill the text with a transparent color. 13 | - Use `webkit-background-clip: text` to clip the background with the text, filling the text with the gradient background as the color. 14 | 15 | ```html 16 |

    Gradient text

    17 | ``` 18 | 19 | ```css 20 | .gradient-text { 21 | background: linear-gradient(#70D6FF, #00072D); 22 | -webkit-text-fill-color: transparent; 23 | -webkit-background-clip: text; 24 | font-size: 32px; 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /snippets/grid-centering.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Grid centering 3 | type: snippet 4 | tags: [layout] 5 | cover: work-hard-computer 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Horizontally and vertically centers a child element within a parent element using `grid`. 10 | 11 | - Use `display: grid` to create a grid layout. 12 | - Use `justify-content: center` to center the child horizontally. 13 | - Use `align-items: center` to center the child vertically. 14 | 15 | ```html 16 |
    17 |
    Centered content.
    18 |
    19 | ``` 20 | 21 | ```css 22 | .grid-centering { 23 | display: grid; 24 | justify-content: center; 25 | align-items: center; 26 | height: 100px; 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /snippets/hamburger-button.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hamburger Button 3 | type: snippet 4 | tags: [interactivity] 5 | cover: volcano-sunset 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Displays a hamburger menu which transitions to a cross button on hover. 10 | 11 | - Use a `.hamburger-menu` container `div` which contains the top, bottom, and middle bars. 12 | - Set the container to `display: flex` with `flex-flow: column wrap`. 13 | - Add distance between the bars using `justify-content: space-between`. 14 | - Use `transform: rotate()` to rotate the top and bottom bars by 45 degrees and `opacity: 0` to fade the middle bar on hover. 15 | - Use `transform-origin: left` so that the bars rotate around the left point. 16 | 17 | ```html 18 |
    19 |
    20 |
    21 |
    22 |
    23 | ``` 24 | 25 | ```css 26 | .hamburger-menu { 27 | display: flex; 28 | flex-flow: column wrap; 29 | justify-content: space-between; 30 | height: 2.5rem; 31 | width: 2.5rem; 32 | cursor: pointer; 33 | } 34 | 35 | .hamburger-menu .bar { 36 | height: 5px; 37 | background: black; 38 | border-radius: 5px; 39 | margin: 3px 0px; 40 | transform-origin: left; 41 | transition: all 0.5s; 42 | } 43 | 44 | .hamburger-menu:hover .top { 45 | transform: rotate(45deg); 46 | } 47 | 48 | .hamburger-menu:hover .middle { 49 | opacity: 0; 50 | } 51 | 52 | .hamburger-menu:hover .bottom { 53 | transform: rotate(-45deg); 54 | } 55 | ``` 56 | -------------------------------------------------------------------------------- /snippets/height-transition.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Height transition 3 | type: snippet 4 | tags: [animation] 5 | cover: washed-ashore 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Transitions an element's height from `0` to `auto` when its height is unknown. 10 | 11 | - Use `transition` to specify that changes to `max-height` should be transitioned over. 12 | - Use `overflow: hidden` to prevent the contents of the hidden element from overflowing its container. 13 | - Use `max-height` to specify an initial height of `0`. 14 | - Use the `:hover` pseudo-class to change the `max-height` to the value of the `--max-height` variable set by JavaScript. 15 | - Use `Element.scrollHeight` and `CSSStyleDeclaration.setProperty()` to set the value of `--max-height` to the current height of the element. 16 | - **Note:** Causes reflow on each animation frame, which will be laggy if there are a large number of elements beneath the element that is transitioning in height. 17 | 18 | ```html 19 |
    20 | Hover me to see a height transition. 21 |
    Additional content
    22 |
    23 | ``` 24 | 25 | ```css 26 | .el { 27 | transition: max-height 0.3s; 28 | overflow: hidden; 29 | max-height: 0; 30 | } 31 | 32 | .trigger:hover > .el { 33 | max-height: var(--max-height); 34 | } 35 | ``` 36 | 37 | ```js 38 | let el = document.querySelector('.el'); 39 | let height = el.scrollHeight; 40 | el.style.setProperty('--max-height', height + 'px'); 41 | ``` 42 | -------------------------------------------------------------------------------- /snippets/hide-empty-elements.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hide empty elements 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: metro-arrival 7 | dateModified: 2022-11-18T05:00:00-04:00 8 | --- 9 | 10 | Hides elements with no content. 11 | 12 | - Use the `:empty` pseudo-class to select elements with no content. 13 | 14 | ```html 15 |

    Lorem ipsum dolor sit amet.

    16 | ``` 17 | 18 | ```css 19 | :empty { 20 | display: none; 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /snippets/hide-scrollbars.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hide scroll bars 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: by-the-lighthouse 7 | dateModified: 2022-05-13T05:00:00-04:00 8 | --- 9 | 10 | Hides scrollbars on an element, while still allowing it to be scrollable. 11 | 12 | - Use `overflow: auto` to allow the element to be scrollable. 13 | - Use `scrollbar-width: none` to hide scrollbars on Firefox. 14 | - Use `display: none` on the `::-webkit-scrollbar` pseudo-element to hide scrollbars on WebKit browsers (Chrome, Edge, Safari). 15 | 16 | ```html 17 |
    18 |

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean interdum id leo a consectetur. Integer justo magna, ultricies vel enim vitae, egestas efficitur leo. Ut nulla orci, rutrum eu augue sed, tempus pellentesque quam.

    19 |
    20 | ``` 21 | 22 | ```css 23 | div { 24 | width: 200px; 25 | height: 100px; 26 | } 27 | 28 | .no-scrollbars { 29 | overflow: auto; 30 | scrollbar-width: none; 31 | } 32 | 33 | .no-scrollbars::-webkit-scrollbar { 34 | display: none; 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /snippets/horizontal-gallery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Image gallery with horizontal scroll 3 | type: snippet 4 | tags: [visual,interactivity] 5 | cover: flower-portrait-5 6 | dateModified: 2022-05-01T05:00:00-04:00 7 | --- 8 | 9 | Creates a horizontally scrollable image gallery. 10 | 11 | - Position the `.thumbnails` at the bottom of the container using `position: absolute`. 12 | - Use `scroll-snap-type: x mandatory` and `overscroll-behavior-x: contain` to create a snap effect on horizontal scroll. Snap elements to the start of the container using `scroll-snap-align: start`. 13 | - Hide scrollbars using `scrollbar-width: none` and styling the pseudo-element `::-webkit-scrollbar` to `display: none`. 14 | - Use `Element.scrollTo()` to define a `scrollToElement` function, that scrolls the gallery to the given item. 15 | - Use `Array.prototype.map()` and `Array.prototype.join()` to populate the `.thumbnails` element. Give each thumbnail a `data-id` attribute with the index of the image. 16 | - Use `Document.querySelectorAll()` to get all the thumbnail elements. Use `Array.prototype.forEach()` to register a handler for the `'click'` event on each thumbnail, using `EventTarget.addEventListener()` and the `scrollToElement` function. 17 | - Use `Document.querySelector()` and `EventTarget.addEventListener()` to register a handler for the `'scroll'` event. Update the `.thumbnails` element to match the current scroll position, using the `highlightThumbnail` function. 18 | 19 | ```html 20 | 34 | ``` 35 | 36 | ```css 37 | .gallery-container { 38 | position: relative; 39 | display: flex; 40 | justify-content: center; 41 | } 42 | 43 | .thumbnails { 44 | position: absolute; 45 | bottom: 8px; 46 | display: flex; 47 | flex-direction: row; 48 | gap: 6px; 49 | } 50 | 51 | .thumbnails div { 52 | width: 8px; 53 | height: 8px; 54 | cursor: pointer; 55 | background: #aaa; 56 | border-radius: 100%; 57 | } 58 | 59 | .thumbnails div.highlighted { 60 | background-color: #777; 61 | } 62 | 63 | .slides { 64 | margin: 0 16px; 65 | display: grid; 66 | grid-auto-flow: column; 67 | gap: 1rem; 68 | width: 540px; 69 | padding: 0 0.25rem; 70 | height: 720px; 71 | overflow-y: auto; 72 | overscroll-behavior-x: contain; 73 | scroll-snap-type: x mandatory; 74 | scrollbar-width: none; 75 | } 76 | 77 | .slides > div { 78 | scroll-snap-align: start; 79 | } 80 | 81 | .slides img { 82 | width: 540px; 83 | object-fit: contain; 84 | } 85 | 86 | .slides::-webkit-scrollbar { 87 | display: none; 88 | } 89 | ``` 90 | 91 | ```js 92 | const slideGallery = document.querySelector('.slides'); 93 | const slides = slideGallery.querySelectorAll('div'); 94 | const thumbnailContainer = document.querySelector('.thumbnails'); 95 | const slideCount = slides.length; 96 | const slideWidth = 540; 97 | 98 | const highlightThumbnail = () => { 99 | thumbnailContainer 100 | .querySelectorAll('div.highlighted') 101 | .forEach(el => el.classList.remove('highlighted')); 102 | const index = Math.floor(slideGallery.scrollLeft / slideWidth); 103 | thumbnailContainer 104 | .querySelector(`div[data-id="${index}"]`) 105 | .classList.add('highlighted'); 106 | }; 107 | 108 | const scrollToElement = el => { 109 | const index = parseInt(el.dataset.id, 10); 110 | slideGallery.scrollTo(index * slideWidth, 0); 111 | }; 112 | 113 | thumbnailContainer.innerHTML += [...slides] 114 | .map((slide, i) => `
    `) 115 | .join(''); 116 | 117 | thumbnailContainer.querySelectorAll('div').forEach(el => { 118 | el.addEventListener('click', () => scrollToElement(el)); 119 | }); 120 | 121 | slideGallery.addEventListener('scroll', e => highlightThumbnail()); 122 | 123 | highlightThumbnail(); 124 | ``` 125 | -------------------------------------------------------------------------------- /snippets/horizontal-scroll-snap.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Horizontal scroll snap 3 | type: snippet 4 | tags: [interactivity] 5 | cover: waves-from-above 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Creates a horizontally scrollable container that will snap on elements when scrolling. 10 | 11 | - Use `display: grid` and `grid-auto-flow: column` to create a horizontal layout. 12 | - Use `scroll-snap-type: x mandatory` and `overscroll-behavior-x: contain` to create a snap effect on horizontal scroll. 13 | - Change `scroll-snap-align` to either `start`, `stop` or `center` to change the snap alignment. 14 | 15 | ```html 16 |
    17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
    27 | ``` 28 | 29 | ```css 30 | .horizontal-snap { 31 | margin: 0 auto; 32 | display: grid; 33 | grid-auto-flow: column; 34 | gap: 1rem; 35 | height: calc(180px + 1rem); 36 | padding: 1rem; 37 | max-width: 480px; 38 | overflow-y: auto; 39 | overscroll-behavior-x: contain; 40 | scroll-snap-type: x mandatory; 41 | } 42 | 43 | .horizontal-snap > a { 44 | scroll-snap-align: center; 45 | } 46 | 47 | .horizontal-snap img { 48 | width: 180px; 49 | max-width: none; 50 | object-fit: contain; 51 | border-radius: 1rem; 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /snippets/hover-additional-content.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Show additional content on hover 3 | type: snippet 4 | tags: [visual] 5 | cover: dark-leaves-5 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Creates a card that displays additional content on hover. 10 | 11 | - Use `overflow: hidden` on the card to hide elements that overflow vertically. 12 | - Use the `:hover` and `:focus-within` pseudo-class selectors to change the card's styling if the element is hovered, focused or any of its descendants are focused. 13 | - Set `transition: 0.3s ease all` to create a transition effect on hover/focus. 14 | 15 | 16 | ```html 17 |
    18 | 19 |

    Lorem ipsum

    20 |
    21 |

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Link to source 22 |

    23 |
    24 |
    25 | ``` 26 | 27 | ```css 28 | .card { 29 | width: 300px; 30 | height: 280px; 31 | padding: 0; 32 | box-shadow: 0 2px 4px 0 rgba(0,0,0,0.1); 33 | border-radius: 8px; 34 | box-sizing: border-box; 35 | overflow: hidden; 36 | } 37 | 38 | .card * { 39 | transition: 0.3s ease all; 40 | } 41 | 42 | .card img { 43 | margin: 0; 44 | width: 300px; 45 | height: 224px; 46 | object-fit: cover; 47 | display: block; 48 | } 49 | 50 | .card h3 { 51 | margin: 0; 52 | padding: 12px 12px 48px; 53 | line-height: 32px; 54 | font-weight: 500; 55 | font-size: 20px; 56 | } 57 | 58 | .card .focus-content { 59 | display: block; 60 | padding: 8px 12px; 61 | } 62 | 63 | .card p { 64 | margin: 0; 65 | line-height: 1.5; 66 | } 67 | 68 | .card:hover img, .card:focus-within img { 69 | margin-top: -80px; 70 | } 71 | 72 | .card:hover h3, .card:focus-within h3 { 73 | padding: 8px 12px 0; 74 | } 75 | ``` 76 | -------------------------------------------------------------------------------- /snippets/hover-perspective.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Perspective transform on hover 3 | type: snippet 4 | tags: [animation] 5 | author: chalarangelo 6 | cover: tropical-bike 7 | dateModified: 2021-05-17T13:58:04+03:00 8 | --- 9 | 10 | Applies a perspective transform with a hover animation to an element. 11 | 12 | - Use `transform` with the `perspective()` and `rotateY()` functions to create a perspective for the element. 13 | - Use a `transition` to update the `transform` attribute's value on hover. 14 | - Change the `rotateY()` value to negative to mirror the perspective effect from left to right. 15 | 16 | ```html 17 |
    18 |
    19 |
    20 |
    21 | ``` 22 | 23 | ```css 24 | .image-card { 25 | display: inline-block; 26 | box-sizing: border-box; 27 | margin: 1rem; 28 | width: 240px; 29 | height: 320px; 30 | padding: 8px; 31 | border-radius: 1rem; 32 | background: url("https://picsum.photos/id/1049/240/320"); 33 | box-shadow: rgba(0, 0, 0, 0.25) 0px 25px 50px -12px; 34 | } 35 | 36 | .perspective-left { 37 | transform: perspective(1500px) rotateY(15deg); 38 | transition: transform 1s ease 0s; 39 | } 40 | 41 | .perspective-left:hover { 42 | transform: perspective(3000px) rotateY(5deg); 43 | } 44 | 45 | .perspective-right { 46 | transform: perspective(1500px) rotateY(-15deg); 47 | transition: transform 1s ease 0s; 48 | } 49 | 50 | .perspective-right:hover { 51 | transform: perspective(3000px) rotateY(-5deg); 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /snippets/hover-shadow-box-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hover shadow box animation 3 | type: snippet 4 | tags: [animation] 5 | unlisted: true 6 | cover: dark-cloud 7 | dateModified: 2021-01-04T12:30:40+02:00 8 | --- 9 | 10 | Creates a shadow box around the text when it is hovered. 11 | 12 | - 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. 13 | - Use `box-shadow` to make the box transparent. 14 | - Use `transition-property` to enable transitions for both `box-shadow` and `transform`. 15 | - Use the `:hover`, `:active` and `:focus` pseudo-class selectors to apply a new `box-shadow` and `transform: scale(1.2)` to change the scale of the text. 16 | 17 | ```html 18 |

    Box it!

    19 | ``` 20 | 21 | ```css 22 | .hover-shadow-box-animation { 23 | display: inline-block; 24 | vertical-align: middle; 25 | transform: perspective(1px) translateZ(0); 26 | box-shadow: 0 0 1px transparent; 27 | margin: 10px; 28 | transition-duration: 0.3s; 29 | transition-property: box-shadow, transform; 30 | } 31 | 32 | .hover-shadow-box-animation:hover, 33 | .hover-shadow-box-animation:focus, 34 | .hover-shadow-box-animation:active { 35 | box-shadow: 1px 10px 10px -10px rgba(0, 0, 24, 0.5); 36 | transform: scale(1.2); 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /snippets/hover-underline-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hover underline animation 3 | type: snippet 4 | tags: [animation] 5 | cover: coffee-phone-tray-2 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Creates an animated underline effect when the user hovers over the text. 10 | 11 | - Use `display: inline-block` to make the underline span just the width of the text content. 12 | - Use the `::after` pseudo-element with `width: 100%` and `position: absolute` to place it below the content. 13 | - Use `transform: scaleX(0)` to initially hide the pseudo-element. 14 | - Use the `:hover` pseudo-class selector to apply `transform: scaleX(1)` and display the pseudo-element on hover. 15 | - Animate `transform` using `transform-origin: left` and an appropriate `transition`. 16 | - Remove the `transform-origin` property to make the transform originate from the center of the element. 17 | 18 | ```html 19 |

    Hover this text to see the effect!

    20 | ``` 21 | 22 | ```css 23 | .hover-underline-animation { 24 | display: inline-block; 25 | position: relative; 26 | color: #0087ca; 27 | } 28 | 29 | .hover-underline-animation::after { 30 | content: ''; 31 | position: absolute; 32 | width: 100%; 33 | transform: scaleX(0); 34 | height: 2px; 35 | bottom: 0; 36 | left: 0; 37 | background-color: #0087ca; 38 | transform-origin: bottom right; 39 | transition: transform 0.25s ease-out; 40 | } 41 | 42 | .hover-underline-animation:hover::after { 43 | transform: scaleX(1); 44 | transform-origin: bottom left; 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /snippets/image-hover-menu.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Menu on image hover 3 | type: snippet 4 | tags: [layout,animation] 5 | cover: compass 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Displays a menu overlay when the user hovers over the image. 10 | 11 | - Use a `
    ` to wrap the `` element and a `
    ` element that will contain the menu links. 12 | - Use the `opacity` and `right` attributes to animate the image on hover, creating a sliding effect. 13 | - Set the `left` attribute of the `
    ` to the negative of the element's `width`. Reset it to `0` when hovering over the parent element to slide in the menu. 14 | - Use `display: flex`, `flex-direction: column` and `justify-content: center` on the `
    ` to vertically center the menu items. 15 | 16 | ```html 17 |
    18 | 19 |
    20 | Home 21 | Pricing 22 | About 23 |
    24 |
    25 | ``` 26 | 27 | ```css 28 | .hover-menu { 29 | position: relative; 30 | overflow: hidden; 31 | margin: 8px; 32 | min-width: 340px; 33 | max-width: 480px; 34 | max-height: 290px; 35 | width: 100%; 36 | background: #000; 37 | text-align: center; 38 | box-sizing: border-box; 39 | } 40 | 41 | .hover-menu * { 42 | box-sizing: border-box; 43 | } 44 | 45 | .hover-menu img { 46 | position: relative; 47 | max-width: 100%; 48 | top: 0; 49 | right: 0; 50 | opacity: 1; 51 | transition: 0.3s ease-in-out; 52 | } 53 | 54 | .hover-menu div { 55 | position: absolute; 56 | top: 0; 57 | left: -120px; 58 | width: 120px; 59 | height: 100%; 60 | padding: 8px 4px; 61 | background: #000; 62 | transition: 0.3s ease-in-out; 63 | display: flex; 64 | flex-direction: column; 65 | justify-content: center; 66 | } 67 | 68 | .hover-menu div a { 69 | display: block; 70 | line-height: 2; 71 | color: #fff; 72 | text-decoration: none; 73 | opacity: 0.8; 74 | padding: 5px 15px; 75 | position: relative; 76 | transition: 0.3s ease-in-out; 77 | } 78 | 79 | .hover-menu div a:hover { 80 | text-decoration: underline; 81 | } 82 | 83 | .hover-menu:hover img { 84 | opacity: 0.5; 85 | right: -120px; 86 | } 87 | 88 | .hover-menu:hover div { 89 | left: 0; 90 | opacity: 1; 91 | } 92 | ``` 93 | -------------------------------------------------------------------------------- /snippets/image-hover-rotate.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Image rotate on hover 3 | type: snippet 4 | tags: [animation,visual] 5 | cover: succulent-1 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Creates a rotate effect for the image on hover. 10 | 11 | - Use the `scale()`, `rotate()` and `transition` properties when hovering over the parent element (a `
    `) to animate the image. 12 | - Use `overflow: hidden` on the parent element to hide the excess from the image transformation. 13 | 14 | ```html 15 |
    16 | 17 |
    18 | ``` 19 | 20 | ```css 21 | .hover-rotate { 22 | overflow: hidden; 23 | margin: 8px; 24 | min-width: 240px; 25 | max-width: 320px; 26 | width: 100%; 27 | } 28 | 29 | .hover-rotate img { 30 | transition: all 0.3s; 31 | box-sizing: border-box; 32 | max-width: 100%; 33 | } 34 | 35 | .hover-rotate:hover img { 36 | transform: scale(1.3) rotate(5deg); 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /snippets/image-mosaic.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Responsive image mosaic 3 | type: snippet 4 | tags: [layout] 5 | author: chalarangelo 6 | cover: beach-riders 7 | dateModified: 2020-12-30T15:37:37+02:00 8 | --- 9 | 10 | Creates a responsive image mosaic. 11 | 12 | - Use `display: grid` to create an appropriate responsive grid layout. 13 | - Use `grid-row: span 2 / auto` and `grid-column: span 2 / auto` to create items that span two rows or two columns respectively. 14 | - Wrap the previous styles into a media query to avoid applying on small screen sizes. 15 | 16 | ```html 17 |
    18 |
    22 |
    26 |
    30 |
    34 |
    38 |
    42 |
    46 |
    50 |
    54 |
    58 |
    62 |
    66 |
    67 | ``` 68 | 69 | ```css 70 | .image-mosaic { 71 | display: grid; 72 | gap: 1rem; 73 | grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 74 | grid-auto-rows: 240px; 75 | } 76 | 77 | .card { 78 | display: flex; 79 | flex-direction: column; 80 | justify-content: center; 81 | align-items: center; 82 | background: #353535; 83 | font-size: 3rem; 84 | color: #fff; 85 | box-shadow: rgba(3, 8, 20, 0.1) 0px 0.15rem 0.5rem, rgba(2, 8, 20, 0.1) 0px 0.075rem 0.175rem; 86 | height: 100%; 87 | width: 100%; 88 | border-radius: 4px; 89 | transition: all 500ms; 90 | overflow: hidden; 91 | background-size: cover; 92 | background-position: center; 93 | background-repeat: no-repeat; 94 | padding: 0; 95 | margin: 0; 96 | } 97 | 98 | @media screen and (min-width: 600px) { 99 | .card-tall { 100 | grid-row: span 2 / auto; 101 | } 102 | 103 | .card-wide { 104 | grid-column: span 2 / auto; 105 | } 106 | } 107 | ``` 108 | -------------------------------------------------------------------------------- /snippets/image-overlay-hover.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Image overlay on hover 3 | type: snippet 4 | tags: [visual,animation] 5 | cover: architectural 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Displays an image overlay effect on hover. 10 | 11 | - Use the `::before` and `::after` pseudo-elements for the top and bottom bars of the overlay respectively. Set their `opacity`, `transform` and `transition` to produce the desired effect. 12 | - Use the `
    ` for the text of the overlay. Set `display: flex`, `flex-direction: column` and `justify-content: center` to center the text into the image. 13 | - Use the `:hover` pseudo-selector to update the `opacity` and `transform` of all the elements and display the overlay. 14 | 15 | ```html 16 |
    17 | 18 |
    19 |

    Lorem
    Ipsum

    20 |
    21 |
    22 | ``` 23 | 24 | ```css 25 | .hover-img { 26 | background-color: #000; 27 | color: #fff; 28 | display: inline-block; 29 | margin: 8px; 30 | max-width: 320px; 31 | min-width: 240px; 32 | overflow: hidden; 33 | position: relative; 34 | text-align: center; 35 | width: 100%; 36 | } 37 | 38 | .hover-img * { 39 | box-sizing: border-box; 40 | transition: all 0.45s ease; 41 | } 42 | 43 | .hover-img::before, 44 | .hover-img::after { 45 | background-color: rgba(0, 0, 0, 0.5); 46 | border-top: 32px solid rgba(0, 0, 0, 0.5); 47 | border-bottom: 32px solid rgba(0, 0, 0, 0.5); 48 | position: absolute; 49 | top: 0; 50 | bottom: 0; 51 | left: 0; 52 | right: 0; 53 | content: ''; 54 | transition: all 0.3s ease; 55 | z-index: 1; 56 | opacity: 0; 57 | transform: scaleY(2); 58 | } 59 | 60 | .hover-img img { 61 | vertical-align: top; 62 | max-width: 100%; 63 | backface-visibility: hidden; 64 | } 65 | 66 | .hover-img figcaption { 67 | position: absolute; 68 | top: 0; 69 | bottom: 0; 70 | left: 0; 71 | right: 0; 72 | align-items: center; 73 | z-index: 1; 74 | display: flex; 75 | flex-direction: column; 76 | justify-content: center; 77 | line-height: 1.1em; 78 | opacity: 0; 79 | z-index: 2; 80 | transition-delay: 0.1s; 81 | font-size: 24px; 82 | font-family: sans-serif; 83 | font-weight: 400; 84 | letter-spacing: 1px; 85 | text-transform: uppercase; 86 | } 87 | 88 | .hover-img:hover::before, 89 | .hover-img:hover::after { 90 | transform: scale(1); 91 | opacity: 1; 92 | } 93 | 94 | .hover-img:hover > img { 95 | opacity: 0.7; 96 | } 97 | 98 | .hover-img:hover figcaption { 99 | opacity: 1; 100 | } 101 | ``` 102 | -------------------------------------------------------------------------------- /snippets/image-text-overlay.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Image with text overlay 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: icebreaker 7 | dateModified: 2023-01-29T05:00:00-04:00 8 | --- 9 | 10 | Displays an image with a text overlay. 11 | 12 | - Use the `
    ` and `
    ` elements to display the image and the text overlay respectively. 13 | - Use a `linear-gradient` to create the overlay effect over the image. 14 | 15 | ```html 16 |
    17 | 18 |
    19 |

    Business
    Pricing

    20 |
    21 |
    22 | ``` 23 | 24 | ```css 25 | .text-overlay-image { 26 | box-sizing: border-box; 27 | position: relative; 28 | margin: 8px; 29 | max-width: 400px; 30 | max-height: 400px; 31 | width: 100%; 32 | } 33 | 34 | .text-overlay-image figcaption { 35 | box-sizing: border-box; 36 | position: absolute; 37 | top: 0; 38 | bottom: 0; 39 | left: 0; 40 | right: 0; 41 | display: flex; 42 | flex-direction: column; 43 | justify-content: flex-end; 44 | background: linear-gradient(0deg, #00000088 30%, #ffffff44 100%); 45 | color: #fff; 46 | padding: 16px; 47 | font-family: sans-serif; 48 | font-weight: 700; 49 | line-height: 1.2; 50 | font-size: 28px; 51 | } 52 | 53 | .text-overlay-image figcaption h3 { 54 | margin: 0; 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /snippets/input-with-prefix.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Input with prefix 3 | type: snippet 4 | tags: [interactivity,visual] 5 | cover: flower-portrait-4 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates an input with a visual, non-editable prefix. 10 | 11 | - Use `display: flex` to create a container element. 12 | - Remove the border and outline from the `` field. Apply them to the parent element instead to make it look like an input box. 13 | - Use the `:focus-within` pseudo-class selector to style the parent element accordingly, when the user interacts with the `` field. 14 | 15 | ```html 16 |
    17 | +30 18 | 19 |
    20 | ``` 21 | 22 | ```css 23 | .input-box { 24 | display: flex; 25 | align-items: center; 26 | max-width: 300px; 27 | background: #fff; 28 | border: 1px solid #a0a0a0; 29 | border-radius: 4px; 30 | padding-left: 0.5rem; 31 | overflow: hidden; 32 | font-family: sans-serif; 33 | } 34 | 35 | .input-box .prefix { 36 | font-weight: 300; 37 | font-size: 14px; 38 | color: #999; 39 | } 40 | 41 | .input-box input { 42 | flex-grow: 1; 43 | font-size: 14px; 44 | background: #fff; 45 | border: none; 46 | outline: none; 47 | padding: 0.5rem; 48 | } 49 | 50 | .input-box:focus-within { 51 | border-color: #777; 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /snippets/isometric-card.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Isometric card 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: guitar-living-room 7 | dateModified: 2021-05-17T14:04:52+03:00 8 | --- 9 | 10 | Creates an isometric card. 11 | 12 | - Use `transform` with `rotateX()` and `rotateY()` as well as a `box-shadow` to create an isometric card. 13 | - Use `transition` to animate the card, creating a lift effect when the user hovers over it. 14 | 15 | ```html 16 |
    17 | ``` 18 | 19 | ```css 20 | .isometric-card { 21 | margin: 0 auto; 22 | transform: rotateX(51deg) rotateZ(43deg); 23 | transform-style: preserve-3d; 24 | background-color: #fcfcfc; 25 | will-change: transform; 26 | width: 240px; 27 | height: 320px; 28 | border-radius: 2rem; 29 | box-shadow: 1px 1px 0 1px #f9f9fb, -1px 0 28px 0 rgba(34, 33, 81, 0.01), 30 | 28px 28px 28px 0 rgba(34, 33, 81, 0.25); 31 | transition: 0.4s ease-in-out transform, 0.3s ease-in-out box-shadow; 32 | } 33 | 34 | .isometric-card:hover { 35 | transform: translate3d(0px, -16px, 0px) rotateX(51deg) rotateZ(43deg); 36 | box-shadow: 1px 1px 0 1px #f9f9fb, -1px 0 28px 0 rgba(34, 33, 81, 0.01), 37 | 54px 54px 28px -10px rgba(34, 33, 81, 0.15); 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /snippets/line-clamp.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Trim multiline text 3 | type: snippet 4 | tags: [layout,visual] 5 | author: chalarangelo 6 | cover: pink-flower-tree 7 | dateModified: 2021-05-16T20:19:13+03:00 8 | --- 9 | 10 | Limit multiline text to a given number of lines. 11 | 12 | - Use `-webkit-line-clamp` to set the maximum number of lines to be displayed. 13 | - Set `display` to `-webkit-box` and `-webkit-box-orient` to `vertical`, as they are required for `-webkit-line-clamp` to be applied. 14 | - Apply `overflow: hidden` to hide any overflow after the text is trimmed. 15 | 16 | ```html 17 |

    18 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec euismod enim eget ultricies sollicitudin. Nunc aliquam arcu arcu, non suscipit metus luctus id. Aliquam sodales turpis ipsum, in vehicula dui tempor sit amet. Nullam quis urna erat. Pellentesque mattis dolor purus. Aliquam nisl urna, tempor a euismod a, placerat in mauris. Phasellus neque quam, dapibus quis nunc at, feugiat suscipit tortor. Duis vel posuere dolor. Phasellus risus erat, lobortis et mi vel, viverra faucibus lectus. Etiam ut posuere sapien. Nulla ultrices dui turpis, interdum consectetur urna tempus at. 19 |

    20 | ``` 21 | 22 | ```css 23 | .excerpt { 24 | display: -webkit-box; 25 | -webkit-line-clamp: 3; 26 | -webkit-box-orient: vertical; 27 | overflow: hidden; 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /snippets/masonry-layout.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Masonry Layout 3 | type: snippet 4 | tags: [layout] 5 | cover: interior-2 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates a masonry-style layout that is especially useful when working with images. 10 | 11 | - Create a masonry-style layout that consists of "bricks" that fall into each other with either a fixed `width` (vertical layout) or a fixed `height` (horizontal layout), forming a perfect fit. Especially useful when working with images. 12 | - Define `.masonry-container` This is the container for the masonry layout and `.masonry-columns`, an inner container in which `.masonry-brick` elements will be placed. 13 | - Apply `display: block` to `.masonry-brick` elements to allow the layout to flow properly. 14 | - Use the `:first-child` pseudo-element selector to apply a different `margin` for the first element to account for its positioning. 15 | - Use CSS variables and media queries for greater flexibility and responsiveness. 16 | 17 | ```html 18 |
    19 |
    20 | An image 25 | Another image 30 | Another image 35 | One more image 40 | And another one 45 | Last one 50 |
    51 |
    52 | ``` 53 | 54 | ```css 55 | /* Container */ 56 | .masonry-container { 57 | --column-count-small: 1; 58 | --column-count-medium: 2; 59 | --column-count-large: 3; 60 | --column-gap: 0.125rem; 61 | padding: var(--column-gap); 62 | } 63 | 64 | /* Columns */ 65 | .masonry-columns { 66 | column-gap: var(--column-gap); 67 | column-count: var(--column-count-small); 68 | column-width: calc(1 / var(--column-count-small) * 100%); 69 | } 70 | 71 | @media only screen and (min-width: 640px) { 72 | .masonry-columns { 73 | column-count: var(--column-count-medium); 74 | column-width: calc(1 / var(--column-count-medium) * 100%); 75 | } 76 | } 77 | 78 | @media only screen and (min-width: 800px) { 79 | .masonry-columns { 80 | column-count: var(--column-count-large); 81 | column-width: calc(1 / var(--column-count-large) * 100%); 82 | } 83 | } 84 | 85 | /* Bricks */ 86 | .masonry-brick { 87 | width: 100%; 88 | height: auto; 89 | margin: var(--column-gap) 0; 90 | display: block; 91 | } 92 | 93 | .masonry-brick:first-child { 94 | margin: 0 0 var(--column-gap); 95 | } 96 | ``` 97 | -------------------------------------------------------------------------------- /snippets/mouse-cursor-gradient-tracking.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mouse cursor gradient tracking 3 | type: snippet 4 | tags: [visual,interactivity] 5 | cover: tram-car 6 | dateModified: 2021-01-07T23:52:15+02:00 7 | --- 8 | 9 | A hover effect where the gradient follows the mouse cursor. 10 | 11 | - Declare two CSS variables, `--x` and `--y`, used to track the position of the mouse on the button. 12 | - Declare a CSS variable, `--size`, used to modify the gradient's dimensions. 13 | - Use `background: radial-gradient(circle closest-side, pink, transparent)` to create the gradient at the correct position. 14 | - Use `Document.querySelector()` and `EventTarget.addEventListener()` to register a handler for the `'mousemove'` event. 15 | - Use `Element.getBoundingClientRect()` and `CSSStyleDeclaration.setProperty()` to update the values of the `--x` and `--y` CSS variables. 16 | 17 | ```html 18 | 21 | ``` 22 | 23 | ```css 24 | .mouse-cursor-gradient-tracking { 25 | position: relative; 26 | background: #7983ff; 27 | padding: 0.5rem 1rem; 28 | font-size: 1.2rem; 29 | border: none; 30 | color: white; 31 | cursor: pointer; 32 | outline: none; 33 | overflow: hidden; 34 | } 35 | 36 | .mouse-cursor-gradient-tracking span { 37 | position: relative; 38 | } 39 | 40 | .mouse-cursor-gradient-tracking::before { 41 | --size: 0; 42 | content: ''; 43 | position: absolute; 44 | left: var(--x); 45 | top: var(--y); 46 | width: var(--size); 47 | height: var(--size); 48 | background: radial-gradient(circle closest-side, pink, transparent); 49 | transform: translate(-50%, -50%); 50 | transition: width 0.2s ease, height 0.2s ease; 51 | } 52 | 53 | .mouse-cursor-gradient-tracking:hover::before { 54 | --size: 200px; 55 | } 56 | ``` 57 | 58 | ```js 59 | let btn = document.querySelector('.mouse-cursor-gradient-tracking'); 60 | btn.addEventListener('mousemove', e => { 61 | let rect = e.target.getBoundingClientRect(); 62 | let x = e.clientX - rect.left; 63 | let y = e.clientY - rect.top; 64 | btn.style.setProperty('--x', x + 'px'); 65 | btn.style.setProperty('--y', y + 'px'); 66 | }); 67 | ``` 68 | -------------------------------------------------------------------------------- /snippets/navigation-list-item-hover-and-focus-effect.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Navigation list item hover and focus effect 3 | type: snippet 4 | tags: [visual] 5 | cover: cloudy-rock-formation 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Creates a custom hover and focus effect for navigation items, using CSS transformations. 10 | 11 | - Use the `::before` pseudo-element at the list item anchor to create a hover effect. Hide it using `transform: scale(0)`. 12 | - Use the `:hover` and `:focus` pseudo-class selectors to transition the pseudo-element to `transform: scale(1)` and show its colored background. 13 | - Prevent the pseudo-element from covering the anchor element by using `z-index`. 14 | 15 | ```html 16 | 23 | ``` 24 | 25 | ```css 26 | .hover-nav ul { 27 | list-style: none; 28 | margin: 0; 29 | padding: 0; 30 | overflow: hidden; 31 | } 32 | 33 | .hover-nav li { 34 | float: left; 35 | } 36 | 37 | .hover-nav li a { 38 | position: relative; 39 | display: block; 40 | color: #fff; 41 | text-align: center; 42 | padding: 8px 12px; 43 | text-decoration: none; 44 | z-index: 0; 45 | } 46 | 47 | li a::before { 48 | position: absolute; 49 | content: ""; 50 | width: 100%; 51 | height: 100%; 52 | bottom: 0; 53 | left: 0; 54 | background-color: #2683f6; 55 | z-index: -1; 56 | transform: scale(0); 57 | transition: transform 0.5s ease-in-out; 58 | } 59 | 60 | li a:hover::before, 61 | li a:focus::before { 62 | transform: scale(1); 63 | } 64 | ``` 65 | -------------------------------------------------------------------------------- /snippets/offscreen.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Offscreen 3 | type: snippet 4 | tags: [layout,visual] 5 | cover: succulent-2 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Hides an element completely (visually and positionally) in the DOM while still allowing it to be accessible. 10 | 11 | - Remove all borders and padding and hide the element's overflow. 12 | - Use `clip` to define that no part of the element is shown. 13 | - Make the `height` and `width` of the element `1px` and negate them using `margin: -1px`. 14 | - Use `position: absolute` so that the element does not take up space in the DOM. 15 | - **Note:** This technique provides an accessible and layout-friendly alternative to `display: none` (not readable by screen readers) and `visibility: hidden` (takes up physical space in the DOM). 16 | 17 | ```html 18 | 19 | Learn More about pants 20 | 21 | ``` 22 | 23 | ```css 24 | .offscreen { 25 | border: 0; 26 | clip: rect(0 0 0 0); 27 | height: 1px; 28 | margin: -1px; 29 | overflow: hidden; 30 | padding: 0; 31 | position: absolute; 32 | width: 1px; 33 | } 34 | ``` 35 | -------------------------------------------------------------------------------- /snippets/overflow-scroll-gradient.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Overflow scroll gradient 3 | type: snippet 4 | tags: [visual] 5 | cover: memories-of-pineapple-1 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled. 10 | 11 | - Use the `::after` pseudo-element to create a `linear-gradient()` that fades from `transparent` to `white` (top to bottom). 12 | - Use `position: absolute`, `width` and `height` to place and size the pseudo-element in its parent. 13 | - Use `pointer-events: none` to exclude the pseudo-element from mouse events, allowing text behind it to still be selectable/interactive. 14 | 15 | ```html 16 |
    17 |
    18 | Lorem ipsum dolor sit amet consectetur adipisicing elit.
    19 | Iure id exercitationem nulla qui repellat laborum vitae,
    20 | molestias tempora velit natus. Quas, assumenda nisi.
    21 | Quisquam enim qui iure, consequatur velit sit?
    22 | Lorem ipsum dolor sit amet consectetur adipisicing elit.
    23 | Iure id exercitationem nulla qui repellat laborum vitae,
    24 | molestias tempora velit natus. Quas, assumenda nisi.
    25 | Quisquam enim qui iure, consequatur velit sit? 26 |
    27 |
    28 | ``` 29 | 30 | ```css 31 | .overflow-scroll-gradient { 32 | position: relative; 33 | } 34 | 35 | .overflow-scroll-gradient::after { 36 | content: ''; 37 | position: absolute; 38 | bottom: 0; 39 | width: 250px; 40 | height: 25px; 41 | background: linear-gradient(transparent, white); 42 | pointer-events: none; 43 | } 44 | 45 | .overflow-scroll-gradient-scroller { 46 | overflow-y: scroll; 47 | background: white; 48 | width: 240px; 49 | height: 200px; 50 | padding: 15px; 51 | line-height: 1.2; 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /snippets/polka-dot-pattern.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Polka dot background pattern 3 | type: snippet 4 | tags: [visual] 5 | cover: bag-waiting 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates a polka dot background pattern. 10 | 11 | - Use `background-color` to set a black background. 12 | - Use `background-image` with two `radial-gradient()` values to create two dots. 13 | - Use `background-size` to specify the pattern's size. Use `background-position` to appropriately place the two gradients. 14 | - **Note:** The fixed `height` and `width` of the element is for demonstration purposes only. 15 | 16 | ```html 17 |
    18 | ``` 19 | 20 | ```css 21 | .polka-dot { 22 | width: 240px; 23 | height: 240px; 24 | background-color: #000; 25 | background-image: radial-gradient(#fff 10%, transparent 11%), 26 | radial-gradient(#fff 10%, transparent 11%); 27 | background-size: 60px 60px; 28 | background-position: 0 0, 30px 30px; 29 | background-repeat: repeat; 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /snippets/popout-menu.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Popout menu 3 | type: snippet 4 | tags: [interactivity] 5 | cover: city-view 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Reveals an interactive popout menu on hover/focus. 10 | 11 | - Use `left: 100%` to move the popout menu to the right of the parent. 12 | - Use `visibility: hidden` to hide the popout menu initially, allowing for transitions to be applied (unlike `display: none`). 13 | - Use the `:hover`, `:focus` and `:focus-within` pseudo-class selectors to apply `visibility: visible` to the popout menu, displaying it when the parent element is hovered/focused. 14 | 15 | ```html 16 |
    17 |
    Popout menu
    18 |
    19 | ``` 20 | 21 | ```css 22 | .reference { 23 | position: relative; 24 | background: tomato; 25 | width: 100px; 26 | height: 80px; 27 | } 28 | 29 | .popout-menu { 30 | position: absolute; 31 | visibility: hidden; 32 | left: 100%; 33 | background: #9C27B0; 34 | color: white; 35 | padding: 16px; 36 | } 37 | 38 | .reference:hover > .popout-menu, 39 | .reference:focus > .popout-menu, 40 | .reference:focus-within > .popout-menu { 41 | visibility: visible; 42 | } 43 | ``` 44 | -------------------------------------------------------------------------------- /snippets/pretty-text-underline.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Pretty text underline 3 | type: snippet 4 | tags: [visual] 5 | cover: flower-portrait-6 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Provides a nicer alternative to `text-decoration: underline` where descenders do not clip the underline. 10 | 11 | - Use `text-shadow` to apply 4 values with offsets covering a 4x4 `px` area. This ensures the underline has a thick shadow that covers the line where descenders clip it. For best results, use a color that matches the `background` and adjust the `px` values for larger fonts. 12 | - Use `background-image` with `linear-gradient()` and `currentColor` to create a gradient that will act as the actual underline. 13 | - Set `background-position`, `background-repeat` and `background-size` to place the gradient in the correct position. 14 | - Use the `::selection` pseudo-class selector to ensure the text shadow does not interfere with text selection. 15 | - **Note:** This is natively implemented as `text-decoration-skip-ink: auto` but it has less control over the underline. 16 | 17 | ```html 18 |
    19 |

    Pretty text underline without clipping descenders.

    20 |
    21 | ``` 22 | 23 | ```css 24 | .container { 25 | background: #f5f6f9; 26 | color: #333; 27 | padding: 8px 0; 28 | } 29 | 30 | .pretty-text-underline { 31 | display: inline; 32 | text-shadow: 1px 1px #f5f6f9, -1px 1px #f5f6f9, -1px -1px #f5f6f9, 33 | 1px -1px #f5f6f9; 34 | background-image: linear-gradient(90deg, currentColor 100%, transparent 100%); 35 | background-position: bottom; 36 | background-repeat: no-repeat; 37 | background-size: 100% 1px; 38 | } 39 | 40 | .pretty-text-underline::selection { 41 | background-color: rgba(0, 150, 255, 0.3); 42 | text-shadow: none; 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /snippets/pulse-loader.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Pulse loader 3 | type: snippet 4 | tags: [animation] 5 | cover: digital-nomad-8 6 | dateModified: 2021-10-13T19:29:39+02:00 7 | --- 8 | 9 | Creates a pulse effect loader animation using the `animation-delay` property. 10 | 11 | - Use `@keyframes` to define an animation at two points in the cycle. At the start (`0%`), the two `
    ` elements have no `width` or `height` and are positioned at the center. At the end (`100%`), both `
    ` elements have increased `width` and `height`, but their `position` is reset to `0`. 12 | - Use `opacity` to transition from `1` to `0` when animating to give the `
    ` elements a disappearing effect as they expand. 13 | - Set a predefined `width` and `height` for the parent container, `.ripple-loader` and use `position: relative` to position its children. 14 | - Use `animation-delay` on the second `
    ` element, so that each element starts its animation at a different time. 15 | 16 | ```html 17 |
    18 |
    19 |
    20 |
    21 | ``` 22 | 23 | ```css 24 | .ripple-loader { 25 | position: relative; 26 | width: 64px; 27 | height: 64px; 28 | } 29 | 30 | .ripple-loader div { 31 | position: absolute; 32 | border: 4px solid #454ADE; 33 | border-radius: 50%; 34 | animation: ripple-loader 1s ease-out infinite; 35 | } 36 | 37 | .ripple-loader div:nth-child(2) { 38 | animation-delay: -0.5s; 39 | } 40 | 41 | @keyframes ripple-loader { 42 | 0% { 43 | top: 32px; 44 | left: 32px; 45 | width: 0; 46 | height: 0; 47 | opacity: 1; 48 | } 49 | 100% { 50 | top: 0; 51 | left: 0; 52 | width: 64px; 53 | height: 64px; 54 | opacity: 0; 55 | } 56 | } 57 | ``` 58 | -------------------------------------------------------------------------------- /snippets/reset-all-styles.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Reset all styles 3 | type: snippet 4 | tags: [visual] 5 | cover: rocky-beach-2 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Resets all styles to default values using only one property. 10 | 11 | - Use the `all` property to reset all styles (inherited or not) to their default values. 12 | - **Note:** This will not affect `direction` and `unicode-bidi` properties. 13 | 14 | ```html 15 |
    16 |
    Title
    17 |

    18 | Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id 19 | exercitationem nulla qui repellat laborum vitae, molestias tempora velit 20 | natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit? 21 |

    22 |
    23 | ``` 24 | 25 | ```css 26 | .reset-all-styles { 27 | all: initial; 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /snippets/responsive-layout-sidebar.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Responsive layout with sidebar 3 | type: snippet 4 | tags: [layout] 5 | author: chalarangelo 6 | cover: red-petals 7 | dateModified: 2020-09-16T18:54:56+03:00 8 | --- 9 | 10 | Creates a responsive layout with a content area and a sidebar. 11 | 12 | - Use `display: grid` on the parent container, to create a grid layout. 13 | - Use `minmax()` for the second column (sidebar) to allow it to take up between `150px` and `20%`. 14 | - Use `1fr` for the first column (main content) to take up the rest of the remaining space. 15 | 16 | ```html 17 |
    18 |
    19 | This element is 1fr large. 20 |
    21 | 24 |
    25 | ``` 26 | 27 | ```css 28 | .container { 29 | display: grid; 30 | grid-template-columns: 1fr minmax(150px, 20%); 31 | height: 100px; 32 | } 33 | 34 | main, aside { 35 | padding: 12px; 36 | text-align: center; 37 | } 38 | 39 | main { 40 | background: #d4f2c4; 41 | } 42 | 43 | aside { 44 | background: #81cfd9; 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /snippets/rotating-card.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rotating Card 3 | type: snippet 4 | tags: [animation] 5 | cover: digital-nomad-11 6 | dateModified: 2021-03-30T15:24:01+03:00 7 | --- 8 | 9 | Creates a two sided card which rotates on hover. 10 | 11 | - Set the `backface-visibility` of the cards to none. 12 | - Initially, set `rotateY()` for the back side of the card to `-180deg` and the front side to `0deg`. 13 | - Upon hover, set `rotateY()` for the front side to `180deg` and backside to `0deg`. 14 | - Set the appropriate `perspective` value to create the rotate effect. 15 | 16 | ```html 17 |
    18 |
    19 |
    Front Side
    20 |
    21 |
    22 |
    Back Side
    23 |
    24 |
    25 | ``` 26 | 27 | ```css 28 | .card { 29 | perspective: 150rem; 30 | position: relative; 31 | height: 40rem; 32 | max-width: 400px; 33 | margin: 2rem; 34 | box-shadow: none; 35 | background: none; 36 | } 37 | 38 | .card-side { 39 | height: 35rem; 40 | border-radius: 15px; 41 | transition: all 0.8s ease; 42 | backface-visibility: hidden; 43 | position: absolute; 44 | top: 0; 45 | left: 0; 46 | width: 80%; 47 | padding: 2rem; 48 | color: white; 49 | } 50 | 51 | .card-side.back { 52 | transform: rotateY(-180deg); 53 | background-color: #4158D0; 54 | background-image: linear-gradient(43deg, #4158D0 0%,#C850C0 46%, #FFCC70 100%); 55 | } 56 | 57 | .card-side.front { 58 | background-color: #0093E9; 59 | background-image: linear-gradient(160deg, #0093E9 0%, #80D0C7 100%); 60 | } 61 | 62 | .card:hover .card-side.front { 63 | transform: rotateY(180deg); 64 | } 65 | 66 | .card:hover .card-side.back { 67 | transform: rotateY(0deg); 68 | } 69 | ``` 70 | -------------------------------------------------------------------------------- /snippets/scroll-progress-bar.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Scroll progress bar 3 | type: snippet 4 | tags: [animation,visual] 5 | author: chalarangelo 6 | cover: coworking-space 7 | dateModified: 2021-10-13T19:29:39+02:00 8 | --- 9 | 10 | Creates a progress bar indicating the scroll percentage of the page. 11 | 12 | - Use `position: fixed` and a large `z-index` value to place the element at the top of the page and above any content. 13 | - Use `EventTarget.addEventListener()` and `Element.scrollTop` to determine the scroll percentage of the document and apply it to the `width` of the element. 14 | 15 | ```html 16 |
    17 | ``` 18 | 19 | ```css 20 | body { 21 | min-height: 200vh; 22 | } 23 | 24 | #scroll-progress { 25 | position: fixed; 26 | top: 0; 27 | width: 0%; 28 | height: 4px; 29 | background: #7983ff; 30 | z-index: 10000; 31 | } 32 | ``` 33 | 34 | ```js 35 | const scrollProgress = document.getElementById('scroll-progress'); 36 | const height = 37 | document.documentElement.scrollHeight - document.documentElement.clientHeight; 38 | 39 | window.addEventListener('scroll', () => { 40 | const scrollTop = 41 | document.body.scrollTop || document.documentElement.scrollTop; 42 | scrollProgress.style.width = `${(scrollTop / height) * 100}%`; 43 | }); 44 | ``` 45 | -------------------------------------------------------------------------------- /snippets/shake-invalid-input.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Shake on invalid input 3 | type: snippet 4 | tags: [animation] 5 | cover: perfect-timing 6 | dateModified: 2022-07-31T18:30:11+03:00 7 | --- 8 | 9 | Creates a shake animation on invalid input. 10 | 11 | - Use the `pattern` attribute to define the regular expression which the input's value must match. 12 | - Use `@keyframes` to define a shake animation, using the `margin-left` property. 13 | - Use the `:invalid` pseudo-class to apply an `animation` to make the element shake. 14 | 15 | ```html 16 | 17 | ``` 18 | 19 | ```css 20 | @keyframes shake { 21 | 0% { 22 | margin-left: 0rem; 23 | } 24 | 25% { 25 | margin-left: 0.5rem; 26 | } 27 | 75% { 28 | margin-left: -0.5rem; 29 | } 30 | 100% { 31 | margin-left: 0rem; 32 | } 33 | } 34 | 35 | input:invalid { 36 | animation: shake 0.2s ease-in-out 0s 2; 37 | box-shadow: 0 0 0.6rem #ff0000; 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /snippets/shape-separator.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Shape separator 3 | type: snippet 4 | tags: [visual] 5 | unlisted: true 6 | cover: shapes 7 | dateModified: 2021-01-04T12:30:40+02:00 8 | --- 9 | 10 | Uses an SVG shape to create a separator between two different blocks. 11 | 12 | - Use the `::after` pseudo-element to create the separator element. 13 | - Use `background-image` to add the SVG (a 24x12 triangle) shape via a data URI. The background image will repeat by default, covering the whole area of the pseudo-element. 14 | - Use the `background` of the parent element to set the desired color for the separator. 15 | 16 | ```html 17 |
    18 | ``` 19 | 20 | ```css 21 | .shape-separator { 22 | position: relative; 23 | height: 48px; 24 | background: #9C27B0; 25 | } 26 | 27 | .shape-separator::after { 28 | content: ''; 29 | 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='transparent'/%3E%3C/svg%3E"); 30 | position: absolute; 31 | width: 100%; 32 | height: 12px; 33 | bottom: 0; 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /snippets/shifting-card.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Shifting Card 3 | type: snippet 4 | tags: [animation] 5 | author: chalarangelo 6 | cover: clouds-n-mountains 7 | dateModified: 2022-12-14T05:00:00-04:00 8 | --- 9 | 10 | Creates a card that shifts on hover. 11 | 12 | - Set the appropriate `perspective` on the `.container` element to allow for the shifting effect. 13 | - Add a `transition` for the `transform` property of the `.card` element. 14 | - Use `Document.querySelector()` to select the `.card` element and add event listeners for the `mousemove` and `mouseout` events. 15 | - Use `Element.getBoundingClientRect()` to get the `x`, `y`, `width`, and `height` of the `.card` element. 16 | - Calculate the relative distance as a value between `-1` and `1` for the `x` and `y` axes and apply it through the `transform` property. 17 | 18 | ```html 19 |
    20 |
    21 |
    22 |

    Card

    23 |

    Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti repellat, consequuntur doloribus voluptate esse iure?

    24 |
    25 |
    26 |
    27 | ``` 28 | 29 | ```css 30 | .container { 31 | display: flex; 32 | padding: 24px; 33 | justify-content: center; 34 | align-items: center; 35 | background: #f3f1fe; 36 | } 37 | 38 | .shifting-card { 39 | width: 350px; 40 | display: flex; 41 | flex-direction: column; 42 | align-items: center; 43 | background: #fff; 44 | border-radius: 10px; 45 | margin: 0.5rem; 46 | transition: transform 0.2s ease-out; 47 | box-shadow: 0 0 5px -2px rgba(0, 0, 0, 0.1); 48 | } 49 | 50 | .shifting-card .content { 51 | text-align: center; 52 | margin: 2rem; 53 | line-height: 1.5; 54 | color: #101010; 55 | } 56 | ``` 57 | 58 | ```js 59 | const card = document.querySelector('.shifting-card'); 60 | const { x, y, width, height } = card.getBoundingClientRect(); 61 | const cx = x + width / 2; 62 | const cy = y + height / 2; 63 | 64 | const handleMove = e => { 65 | const { pageX, pageY } = e; 66 | const dx = (cx - pageX) / (width / 2); 67 | const dy = (cy - pageY) / (height / 2); 68 | e.target.style.transform = 69 | `rotateX(${10 * dy * -1}deg) rotateY(${10 * dx}deg)`; 70 | }; 71 | 72 | const handleOut = e => { 73 | e.target.style.transform = 'initial'; 74 | }; 75 | 76 | card.addEventListener('mousemove', handleMove); 77 | card.addEventListener('mouseout', handleOut); 78 | ``` 79 | -------------------------------------------------------------------------------- /snippets/sibling-fade.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Sibling fade 3 | type: snippet 4 | tags: [interactivity] 5 | cover: messy-papers 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Fades out the siblings of a hovered item. 10 | 11 | - Use a `transition` to animate changes to `opacity`. 12 | - Use the `:hover` and `:not` pseudo-class selectors to change the `opacity` of all elements except for the one the mouse is over to `0.5`. 13 | 14 | ```html 15 |
    16 | Item 1 Item 2 Item 3 17 | Item 4 Item 5 Item 6 18 |
    19 | ``` 20 | 21 | ```css 22 | span { 23 | padding: 0 16px; 24 | transition: opacity 0.3s; 25 | } 26 | 27 | .sibling-fade:hover span:not(:hover) { 28 | opacity: 0.5; 29 | } 30 | ``` 31 | -------------------------------------------------------------------------------- /snippets/squiggle-link-hover-effect.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Squiggle link hover effect 3 | type: snippet 4 | tags: [animation,visual] 5 | author: chalarangelo 6 | cover: dreamy-flowers 7 | dateModified: 2023-01-10T05:00:00-04:00 8 | --- 9 | 10 | Creates a squiggle effect when hovering over a link. 11 | 12 | - Create a repeating background for the link using a `linear-gradient`. 13 | - Create a `:hover` state for the link with a `background-image` of a data URL containing an SVG with a squiggly path and an animation. 14 | 15 | ```html 16 |

    The magnificent octopus swam along gracefully.

    17 | ``` 18 | 19 | ```css 20 | a.squiggle { 21 | background: linear-gradient(to bottom, #0087ca 0%, #0087ca 100%); 22 | background-position: 0 100%; 23 | background-repeat: repeat-x; 24 | background-size: 2px 2px; 25 | color: inherit; 26 | text-decoration: none; 27 | } 28 | 29 | a.squiggle:hover { 30 | background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 4'%3E%3Cstyle type='text/css'%3E.squiggle{animation:shift .3s linear infinite;}@keyframes shift {from {transform:translateX(0);}to {transform:translateX(-15px);}}%3C/style%3E%3Cpath fill='none' stroke='%230087ca' stroke-width='2' class='squiggle' d='M0,3.5 c 5,0,5,-3,10,-3 s 5,3,10,3 c 5,0,5,-3,10,-3 s 5,3,10,3'/%3E%3C/svg%3E"); 31 | background-size: auto 4px; 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /snippets/staggered-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Staggered animation 3 | type: snippet 4 | tags: [animation] 5 | cover: aerial-view-port 6 | dateModified: 2021-10-11T18:44:51+03:00 7 | --- 8 | 9 | Creates a staggered animation for the elements of a list. 10 | 11 | - Set `opacity: 0` and `transform: translateX(100%)` to make list elements transparent and move them all the way to the right. 12 | - Specify the same `transition` properties for list elements, except `transition-delay`. 13 | - Use inline styles to specify a value for `--i` for each list element. This will in turn be used for `transition-delay` to create the stagger effect. 14 | - Use the `:checked` pseudo-class selector for the checkbox to style list elements. Set `opacity` to `1` and `transform` to `translateX(0)` to make them appear and slide into view. 15 | 16 | ```html 17 |
    18 | 19 | 20 |
      21 |
    • Home
    • 22 |
    • Pricing
    • 23 |
    • Account
    • 24 |
    • Support
    • 25 |
    • About
    • 26 |
    27 |
    28 | ``` 29 | 30 | ```css 31 | .container { 32 | overflow-x: hidden; 33 | width: 100%; 34 | } 35 | 36 | .menu-toggler { 37 | display: none; 38 | } 39 | 40 | .menu-toggler-label { 41 | cursor: pointer; 42 | font-size: 20px; 43 | font-weight: bold; 44 | } 45 | 46 | .stagger-menu { 47 | list-style-type: none; 48 | margin: 16px 0; 49 | padding: 0; 50 | } 51 | 52 | .stagger-menu li { 53 | margin-bottom: 8px; 54 | font-size: 18px; 55 | opacity: 0; 56 | transform: translateX(100%); 57 | transition-property: opacity, transform; 58 | transition-duration: 0.3s; 59 | transition-timing-function: cubic-bezier(0.750, -0.015, 0.565, 1.055); 60 | } 61 | 62 | .menu-toggler:checked ~ .stagger-menu li { 63 | opacity: 1; 64 | transform: translateX(0); 65 | transition-delay: calc(0.055s * var(--i)); 66 | } 67 | ``` 68 | -------------------------------------------------------------------------------- /snippets/sticky-list-titles.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: List with sticky section headings 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: interior-7 7 | dateModified: 2020-12-30T15:37:37+02:00 8 | --- 9 | 10 | Creates a list with sticky headings for each section. 11 | 12 | - Use `overflow-y: auto` to allow the list container (`
    `) to overflow vertically. 13 | - Set headings (`
    `) `position` to `sticky` and apply `top: 0` to stick to the top of the container. 14 | 15 | ```html 16 |
    17 |
    18 |
    A
    19 |
    Algeria
    20 |
    Angola
    21 | 22 |
    B
    23 |
    Benin
    24 |
    Botswana
    25 |
    Burkina Faso
    26 |
    Burundi
    27 | 28 |
    C
    29 |
    Cabo Verde
    30 |
    Cameroon
    31 |
    Central African Republic
    32 |
    Chad
    33 |
    Comoros
    34 |
    Congo, Democratic Republic of the
    35 |
    Congo, Republic of the
    36 |
    Cote d'Ivoire
    37 | 38 |
    D
    39 |
    Djibouti
    40 | 41 |
    E
    42 |
    Egypt
    43 |
    Equatorial Guinea
    44 |
    Eritrea
    45 |
    Eswatini (formerly Swaziland)
    46 |
    Ethiopia
    47 |
    48 |
    49 | ``` 50 | 51 | ```css 52 | .container { 53 | display: grid; 54 | place-items: center; 55 | min-height: 400px; 56 | } 57 | 58 | .sticky-stack { 59 | background: #37474f; 60 | color: #fff; 61 | margin: 0; 62 | height: 320px; 63 | border-radius: 1rem; 64 | overflow-y: auto; 65 | } 66 | 67 | .sticky-stack dt { 68 | position: sticky; 69 | top: 0; 70 | font-weight: bold; 71 | background: #263238; 72 | color: #cfd8dc; 73 | padding: 0.25rem 1rem; 74 | } 75 | 76 | .sticky-stack dd { 77 | margin: 0; 78 | padding: 0.75rem 1rem; 79 | } 80 | 81 | .sticky-stack dd + dt { 82 | margin-top: 1rem; 83 | } 84 | ``` 85 | -------------------------------------------------------------------------------- /snippets/stripes-pattern.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Stripes background pattern 3 | type: snippet 4 | tags: [visual] 5 | cover: jars-on-shelf 6 | dateModified: 2021-01-11T09:51:43+02:00 7 | --- 8 | 9 | Creates a stripes background pattern. 10 | 11 | - Use `background-color` to set a white background. 12 | - Use `background-image` with a `radial-gradient()` value to create a vertical stripe. 13 | - Use `background-size` to specify the pattern's size. 14 | - **Note:** The fixed `height` and `width` of the element is for demonstration purposes only. 15 | 16 | ```html 17 |
    18 | ``` 19 | 20 | ```css 21 | .stripes { 22 | width: 240px; 23 | height: 240px; 24 | background-color: #fff; 25 | background-image: linear-gradient(90deg, transparent 50%, #000 50%); 26 | background-size: 60px 60px; 27 | background-repeat: repeat; 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /snippets/stylized-quotation-marks.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Stylized quotation marks 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: coffee-phone-tray 7 | dateModified: 2021-05-16T19:53:02+03:00 8 | --- 9 | 10 | Customizes the style of inline quotation marks. 11 | 12 | - Use the `quotes` property to customize the characters used for the opening and closing quotes of a `` element. 13 | 14 | ```html 15 |

    16 | Do or do not, there is no try. – Yoda 17 |

    18 | ``` 19 | 20 | ```css 21 | q { 22 | quotes: "“" "”"; 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /snippets/system-font-stack.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: System font stack 3 | type: snippet 4 | tags: [visual] 5 | cover: lavender-shelf 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Uses the native font of the operating system to get close to a native app feel. 10 | 11 | - Define a list of fonts using `font-family`. 12 | - 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). 13 | - `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however). 14 | - `BlinkMacSystemFont` is San Francisco, used on macOS Chrome. 15 | - `'Segoe UI'` is used on Windows 10. 16 | - `Roboto` is used on Android. 17 | - `Oxygen-Sans` is used on Linux with KDE. 18 | - `Ubuntu` is used on Ubuntu (all variants). 19 | - `Cantarell` is used on Linux with GNOME Shell. 20 | - `'Helvetica Neue'` and `Helvetica` is used on macOS 10.10 and below. 21 | - `Arial` is a font widely supported by all operating systems. 22 | - `sans-serif` is the fallback sans serif font if none of the other fonts are supported. 23 | 24 | ```html 25 |

    This text uses the system font.

    26 | ``` 27 | 28 | ```css 29 | .system-font-stack { 30 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 31 | Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, 32 | sans-serif; 33 | } 34 | ``` 35 | -------------------------------------------------------------------------------- /snippets/text-backdrop-overlay.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Image text overlay 3 | type: snippet 4 | tags: [visual] 5 | author: chalarangelo 6 | cover: mountain-lake-cottage 7 | dateModified: 2021-10-13T19:29:39+02:00 8 | --- 9 | 10 | Displays a text on top of an image using an overlay. 11 | 12 | - Use `backdrop-filter` to apply a `blur(14px)` and `brightness(80%)` effect. This makes text readable regardless of background image and color. 13 | 14 | ```html 15 |
    16 |

    Hello, World

    17 | 18 |
    19 | ``` 20 | 21 | ```css 22 | div { 23 | position: relative; 24 | } 25 | 26 | .text-overlay { 27 | position: absolute; 28 | top: 0; 29 | left: 0; 30 | padding: 1rem; 31 | font-size: 2rem; 32 | font-weight: 300; 33 | color: white; 34 | backdrop-filter: blur(14px) brightness(80%); 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /snippets/tile-layout-using-inline-block.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 3-tile layout 3 | type: snippet 4 | tags: [layout] 5 | cover: godray-computer-mug 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Aligns items horizontally using `display: inline-block` to create a 3-tile layout. 10 | 11 | - Use `display: inline-block` to create a tiled layout, without using `float`, `flex` or `grid`. 12 | - Use `width` in combination with `calc` to divide the width of the container evenly into 3 columns. 13 | - Set `font-size` for `.tiles` to `0` to avoid whitespace and to `20px` for `

    ` elements to display the text. 14 | - **Note:** If you use relative units (e.g. `em`), using `font-size: 0` to fight whitespace between blocks might cause side effects. 15 | 16 | ```html 17 |
    18 |
    19 | 20 |

    30 Seconds of CSS

    21 |
    22 |
    23 | 24 |

    30 Seconds of CSS

    25 |
    26 |
    27 | 28 |

    30 Seconds of CSS

    29 |
    30 |
    31 | ``` 32 | 33 | ```css 34 | .tiles { 35 | width: 600px; 36 | font-size: 0; 37 | margin: 0 auto; 38 | } 39 | 40 | .tile { 41 | width: calc(600px / 3); 42 | display: inline-block; 43 | } 44 | 45 | .tile h2 { 46 | font-size: 20px; 47 | } 48 | ``` 49 | -------------------------------------------------------------------------------- /snippets/toggle-switch.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Toggle switch 3 | type: snippet 4 | tags: [visual,interactivity] 5 | cover: interior-5 6 | dateModified: 2020-12-30T15:37:37+02:00 7 | --- 8 | 9 | Creates a toggle switch with CSS only. 10 | 11 | - Use the `for` attribute to associate the `