Merge branch 'master' into donut-spinner
This commit is contained in:
116
LICENSE
Normal file
116
LICENSE
Normal file
@ -0,0 +1,116 @@
|
||||
CC0 1.0 Universal
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||
subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||
purpose of contributing to a commons of creative, cultural and scientific
|
||||
works ("Commons") that the public can reliably and without fear of later
|
||||
claims of infringement build upon, modify, incorporate in other works, reuse
|
||||
and redistribute as freely as possible in any form whatsoever and for any
|
||||
purposes, including without limitation commercial purposes. These owners may
|
||||
contribute to the Commons to promote the ideal of a free culture and the
|
||||
further production of creative, cultural and scientific works, or to gain
|
||||
reputation or greater distribution for their Work in part through the use and
|
||||
efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any expectation
|
||||
of additional consideration or compensation, the person associating CC0 with a
|
||||
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
||||
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
||||
and publicly distribute the Work under its terms, with knowledge of his or her
|
||||
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||
effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not limited
|
||||
to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
||||
and translate a Work;
|
||||
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
|
||||
iii. publicity and privacy rights pertaining to a person's image or likeness
|
||||
depicted in a Work;
|
||||
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data in
|
||||
a Work;
|
||||
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation thereof,
|
||||
including any amended or successor version of such directive); and
|
||||
|
||||
vii. other similar, equivalent or corresponding rights throughout the world
|
||||
based on applicable law or treaty, and any national implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
||||
and Related Rights and associated claims and causes of action, whether now
|
||||
known or unknown (including existing as well as future claims and causes of
|
||||
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||
duration provided by applicable law or treaty (including future time
|
||||
extensions), (iii) in any current or future medium and for any number of
|
||||
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
||||
the Waiver for the benefit of each member of the public at large and to the
|
||||
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
||||
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||
by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||
shall be preserved to the maximum extent permitted taking into account
|
||||
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
||||
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
||||
non transferable, non sublicensable, non exclusive, irrevocable and
|
||||
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
||||
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
||||
provided by applicable law or treaty (including future time extensions), (iii)
|
||||
in any current or future medium and for any number of copies, and (iv) for any
|
||||
purpose whatsoever, including without limitation commercial, advertising or
|
||||
promotional purposes (the "License"). The License shall be deemed effective as
|
||||
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
||||
License for any reason be judged legally invalid or ineffective under
|
||||
applicable law, such partial invalidity or ineffectiveness shall not
|
||||
invalidate the remainder of the License, and in such case Affirmer hereby
|
||||
affirms that he or she will not (i) exercise any of his or her remaining
|
||||
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
||||
and causes of action with respect to the Work, in either case contrary to
|
||||
Affirmer's express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
|
||||
b. Affirmer offers the Work as-is and makes no representations or warranties
|
||||
of any kind concerning the Work, express, implied, statutory or otherwise,
|
||||
including without limitation warranties of title, merchantability, fitness
|
||||
for a particular purpose, non infringement, or the absence of latent or
|
||||
other defects, accuracy, or the present or absence of errors, whether or not
|
||||
discoverable, all to the greatest extent permissible under applicable law.
|
||||
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without limitation
|
||||
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
||||
disclaims responsibility for obtaining any necessary consents, permissions
|
||||
or other rights required for any use of the Work.
|
||||
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to this
|
||||
CC0 or use of the Work.
|
||||
|
||||
For more information, please see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
@ -1,5 +1,7 @@
|
||||
# 30 Seconds of CSS
|
||||
|
||||

|
||||
|
||||
A curated collection of useful CSS snippets you can understand in 30 seconds or less.
|
||||
Inspired by [30 seconds of code](https://github.com/Chalarangelo/30-seconds-of-code).
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
908
docs/index.html
908
docs/index.html
File diff suppressed because one or more lines are too long
51
index.html
51
index.html
@ -1,3 +1,5 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
@ -8,9 +10,9 @@
|
||||
<script async="" defer="" src="https://buttons.github.io/buttons.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<button class="back-to-top-button">↑</button>
|
||||
<aside class="sidebar">
|
||||
<button class="hamburger hamburger--spin sidebar__menu" type="button">
|
||||
<button class="back-to-top-button" aria-label="back to top">↑</button>
|
||||
<nav class="sidebar" aria-label="Table of Contents">
|
||||
<button class="hamburger hamburger--spin sidebar__menu" type="button" aria-label="Menu">
|
||||
<span class="hamburger-box">
|
||||
<span class="hamburger-inner"></span>
|
||||
</span>
|
||||
@ -34,7 +36,7 @@
|
||||
<a class="sidebar__link" href="#triangle">Triangle</a>
|
||||
<a class="sidebar__link" href="#truncate-text">Truncate text</a>
|
||||
</div>
|
||||
</aside>
|
||||
</nav>
|
||||
<div class="content-wrapper">
|
||||
<header class="header">
|
||||
<div class="container">
|
||||
@ -43,12 +45,10 @@
|
||||
<p class="header__description">
|
||||
A curated collection of useful CSS snippets you can understand in 30 seconds or less.
|
||||
</p>
|
||||
|
||||
<!-- Place this tag where you want the button to render. -->
|
||||
<a class="github-button header__github-button" href="https://github.com/atomiks/30-seconds-of-css" data-icon="octicon-star" data-size="large" aria-label="Star atomiks/30-seconds-of-css on GitHub">Star</a>
|
||||
<a class="github-button header__github-button" href="https://github.com/atomiks/30-seconds-of-css" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star atomiks/30-seconds-of-css on GitHub">Star</a>
|
||||
</div>
|
||||
</header>
|
||||
<main class="main">
|
||||
<main class="main" id="main">
|
||||
<div class="container">
|
||||
<div class="snippet">
|
||||
<h3 id="clearfix">Clearfix</h3>
|
||||
@ -125,8 +125,8 @@
|
||||
}
|
||||
</style>
|
||||
<h4 data-type="Explanation">Explanation</h4>
|
||||
<p><code>padding-top</code> and <code>padding-bottom</code> can be used as an alternative to <code>height</code> such that the percentage value causes an element's height to become a percentage of its width, i.e. <code>50%</code> means the height
|
||||
will be 50% of the element's width. This allows its proportion to remain constant.</p>
|
||||
<p><code>padding-top</code> and <code>padding-bottom</code> can be used as an alternative to <code>height</code> such that the percentage value causes an element's height to become a percentage of its parent's width, i.e. <code>50%</code> means
|
||||
the height will be 50% of the parent element's width, which means it acts the same as <code>width</code>. This allows its proportion to remain constant.</p>
|
||||
<h4 data-type="Browser support">Browser support</h4>
|
||||
<div>
|
||||
<div class="snippet__browser-support">
|
||||
@ -666,6 +666,7 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
width: 300px;
|
||||
height: 25px;
|
||||
background: linear-gradient(rgba(255, 255, 255, 0.001), white); /* transparent keyword is broken in Safari */
|
||||
pointer-events: none;
|
||||
}
|
||||
.overflow-scroll-gradient__scroller {
|
||||
overflow-y: scroll;
|
||||
@ -696,6 +697,7 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
width: 300px;
|
||||
height: 25px;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.snippet-demo__overflow-scroll-gradient__scroller {
|
||||
overflow-y: scroll;
|
||||
@ -712,13 +714,14 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
</script>
|
||||
<h4 data-type="Explanation">Explanation</h4>
|
||||
<ol>
|
||||
<li><code>position: relative</code> on the parent establishes a Cartesian positioning context for psuedo elements.</li>
|
||||
<li><code>position: relative</code> on the parent establishes a Cartesian positioning context for psuedo-elements.</li>
|
||||
<li><code>::after</code> defines a pseudo element.</li>
|
||||
<li><code>background-image: linear-gradient(...)</code> adds a linear gradient that fades from transparent to white (top to bottom).</li>
|
||||
<li><code>position: absolute</code> takes the pseudo element out of the flow of the document and positions it in relation to the parent.</li>
|
||||
<li><code>width: 300px</code> matches the size of the scrolling element (which is a child of the parent that has the pseudo element).</li>
|
||||
<li><code>height: 25px</code> is the height of the fading gradient psuedo element, which should be kept relatively small.</li>
|
||||
<li><code>bottom: 0</code> positions the pseudo element at the bottom of the parent.</li>
|
||||
<li><code>height: 25px</code> is the height of the fading gradient psuedo-element, which should be kept relatively small.</li>
|
||||
<li><code>bottom: 0</code> positions the pseudo-element at the bottom of the parent.</li>
|
||||
<li><code>pointer-events: none</code> specifies that the psuedo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.</li>
|
||||
</ol>
|
||||
<h4 data-type="Browser support">Browser support</h4>
|
||||
<div>
|
||||
@ -809,16 +812,20 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
</code></pre>
|
||||
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.pretty-text-underline {
|
||||
display: inline;
|
||||
font-size: 1.25rem;
|
||||
font-size: 18px;
|
||||
text-shadow: 1px 1px 0 #f5f6f9,
|
||||
-1px 1px 0 #f5f6f9,
|
||||
-1px -1px 0 #f5f6f9,
|
||||
1px -1px 0 #f5f6f9;
|
||||
background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
|
||||
background-position: 0 1.04em;
|
||||
background-position: 0 18px;
|
||||
background-repeat: repeat-x;
|
||||
background-size: 1px 1px;
|
||||
}
|
||||
.pretty-text-underline::-moz-selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
}
|
||||
.pretty-text-underline::selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
@ -834,10 +841,14 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
font-size: 18px !important;
|
||||
text-shadow: 1px 1px 0 #f5f6f9, -1px 1px 0 #f5f6f9, -1px -1px 0 #f5f6f9, 1px -1px 0 #f5f6f9;
|
||||
background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
|
||||
background-position: 0 1.04em;
|
||||
background-position: 0 18px;
|
||||
background-repeat: repeat-x;
|
||||
background-size: 1px 1px;
|
||||
}
|
||||
.snippet-demo__pretty-text-underline::-moz-selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
}
|
||||
.snippet-demo__pretty-text-underline::selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
@ -858,7 +869,7 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
94.8%
|
||||
</div>
|
||||
</div>
|
||||
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||
<p><span class="snippet__support-note">⚠️ Firefox requires a vendor prefix for the selection pseudo-selector to work.</span></p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://caniuse.com/#feat=css-textshadow" target="_blank">https://caniuse.com/#feat=css-textshadow</a>
|
||||
@ -1044,7 +1055,7 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
</div>
|
||||
<div class="snippet">
|
||||
<h3 id="truncate-text">Truncate text</h3>
|
||||
<p>If the text is longer than one line, it will be truncated and end with an ellipsis <code>...</code>.</p>
|
||||
<p>If the text is longer than one line, it will be truncated and end with an ellipsis <code>…</code>.</p>
|
||||
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="truncate-text">If I exceed one line's width, I will be truncated.</p>
|
||||
</code></pre>
|
||||
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.truncate-text {
|
||||
@ -1080,7 +1091,7 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
98.1%
|
||||
</div>
|
||||
</div>
|
||||
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||
<p><span class="snippet__support-note">⚠️ Only works for single line elements.</span></p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://caniuse.com/#feat=text-overflow" target="_blank">https://caniuse.com/#feat=text-overflow</a>
|
||||
@ -1092,4 +1103,4 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
</div>
|
||||
<footer class="footer"></footer>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -67,4 +67,10 @@ for (const snippetFile of fs.readdirSync(SNIPPETS_PATH)) {
|
||||
)
|
||||
}
|
||||
|
||||
fs.writeFileSync('./index.html', pretty(document.documentElement.outerHTML, { ocd: true }))
|
||||
// doctype declaration gets stripped, add it back in
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
${pretty(document.documentElement.outerHTML, { ocd: true })}
|
||||
`
|
||||
|
||||
fs.writeFileSync('./index.html', html)
|
||||
|
||||
@ -38,7 +38,7 @@ Resize your browser window to see the proportion of the element remain the same.
|
||||
#### Explanation
|
||||
|
||||
`padding-top` and `padding-bottom` can be used as an alternative to `height` such that the percentage value
|
||||
causes an element's height to become a percentage of its width, i.e. `50%` means the height will be 50% of the element's width. This allows its proportion to remain constant.
|
||||
causes an element's height to become a percentage of its parent's width, i.e. `50%` means the height will be 50% of the parent element's width, which means it acts the same as `width`. This allows its proportion to remain constant.
|
||||
|
||||
#### Browser support
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
|
||||
width: 300px;
|
||||
height: 25px;
|
||||
background: linear-gradient(rgba(255, 255, 255, 0.001), white); /* transparent keyword is broken in Safari */
|
||||
pointer-events: none;
|
||||
}
|
||||
.overflow-scroll-gradient__scroller {
|
||||
overflow-y: scroll;
|
||||
@ -58,6 +59,7 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
|
||||
width: 300px;
|
||||
height: 25px;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.snippet-demo__overflow-scroll-gradient__scroller {
|
||||
overflow-y: scroll;
|
||||
@ -76,15 +78,16 @@ document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').inne
|
||||
|
||||
#### Explanation
|
||||
|
||||
1. `position: relative` on the parent establishes a Cartesian positioning context for psuedo elements.
|
||||
1. `position: relative` on the parent establishes a Cartesian positioning context for psuedo-elements.
|
||||
2. `::after` defines a pseudo element.
|
||||
3. `background-image: linear-gradient(...)` adds a linear gradient that fades from transparent to white
|
||||
(top to bottom).
|
||||
4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
|
||||
5. `width: 300px` matches the size of the scrolling element (which is a child of the parent that has
|
||||
the pseudo element).
|
||||
6. `height: 25px` is the height of the fading gradient psuedo element, which should be kept relatively small.
|
||||
7. `bottom: 0` positions the pseudo element at the bottom of the parent.
|
||||
6. `height: 25px` is the height of the fading gradient psuedo-element, which should be kept relatively small.
|
||||
7. `bottom: 0` positions the pseudo-element at the bottom of the parent.
|
||||
8. `pointer-events: none` specifies that the psuedo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.
|
||||
|
||||
#### Browser support
|
||||
|
||||
|
||||
@ -14,16 +14,20 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
|
||||
```css
|
||||
.pretty-text-underline {
|
||||
display: inline;
|
||||
font-size: 1.25rem;
|
||||
font-size: 18px;
|
||||
text-shadow: 1px 1px 0 #f5f6f9,
|
||||
-1px 1px 0 #f5f6f9,
|
||||
-1px -1px 0 #f5f6f9,
|
||||
1px -1px 0 #f5f6f9;
|
||||
background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
|
||||
background-position: 0 1.04em;
|
||||
background-position: 0 18px;
|
||||
background-repeat: repeat-x;
|
||||
background-size: 1px 1px;
|
||||
}
|
||||
.pretty-text-underline::-moz-selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
}
|
||||
.pretty-text-underline::selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
@ -45,11 +49,16 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
|
||||
-1px -1px 0 #f5f6f9,
|
||||
1px -1px 0 #f5f6f9;
|
||||
background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
|
||||
background-position: 0 1.04em;
|
||||
background-position: 0 18px;
|
||||
background-repeat: repeat-x;
|
||||
background-size: 1px 1px;
|
||||
}
|
||||
|
||||
.snippet-demo__pretty-text-underline::-moz-selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
.snippet-demo__pretty-text-underline::selection {
|
||||
background-color: rgba(0, 150, 255, 0.3);
|
||||
text-shadow: none;
|
||||
@ -69,7 +78,7 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
<span class="snippet__support-note">⚠️ Firefox requires a vendor prefix for the selection pseudo-selector to work.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-textshadow
|
||||
* https://caniuse.com/#feat=css-gradients
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
### Truncate text
|
||||
|
||||
If the text is longer than one line, it will be truncated and end with an ellipsis `...`.
|
||||
If the text is longer than one line, it will be truncated and end with an ellipsis `…`.
|
||||
|
||||
#### HTML
|
||||
|
||||
@ -46,6 +46,6 @@ If the text is longer than one line, it will be truncated and end with an ellips
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
<span class="snippet__support-note">⚠️ Only works for single line elements.</span>
|
||||
|
||||
* https://caniuse.com/#feat=text-overflow
|
||||
|
||||
Reference in New Issue
Block a user