Quickref Me Css3
Quickref Me Css3
5k Follow Me
CSS 3 cheatsheet
This is a quick reference cheat sheet for CSS goodness, listing selector syntax, properties, units
and other useful bits of information.
# Getting Started
- Introduction Add class !important
CSS is rich in capabilities and is more than simply <div class="classname"></div> .post-title {
laying out pages. <div class="class1 ... classn"></div> color: blue !important;
}
External stylesheet
<link Support multiple classes on one element. Overrides all previous styling rules.
href="./path/to/stylesheet/style.css"
rel="stylesheet" type="text/css">
Selector Text color
Internal stylesheet
h1 { } color: #2a2aff;
<style> #job-title { } color: green;
div.hero { } color: rgb(34, 12, 64, 0.6);
body {
div > p { } color: hsla(30 100% 50% / 0.6);
background-color: linen;
}
</style> See: Selectors See: Colors
Inline styles
Background Font
<h2 style="text-align: center;">Centered
text</h2> background-color: blue; .page-title {
background-image: url("nyan-cat.gif"); font-weight: bold;
<p style="color: blue; font-size: background-image: url("../image.png"); font-size: 30px;
18px;">Blue, 18-point text</p> font-family: "Courier New";
}
.box {
position: relative; animation: 300ms linear 0s infinite; /* This is a single line comment */
top: 20px;
left: 20px; animation: bounce 300ms linear infinite; /* This is a
} multi-line comment */
See: Flexbox | Flex Tricks See: Grid Layout See: Dynamic content
# CSS Selectors
- Examples Basic Combinators
Groups Selector * All elements div.classname Div with certain classname
p::after Add content after p input:checked Checked inputs p:first-child First child
p::before Add content before p input:disabled Disabled inputs p:last-child Last child
p::first-letter First letter in p input:enabled Enabled inputs p:first-of-type First of some type
p::first-line First line in p input:focus Input has focus p:last-of-type Last of some type
:target Highlight active anchor input:invalid Input with invalid value Second child from
p:nth-last-child(2)
behind
div:empty Element with no children input:optional No required attribute
p:nth-of-type(2) Second p of its parent
p:lang(en) P with en language attribute Input with required
input:required p:nth-last-of-type(2) ...from behind
attribute
:not(span) Element that's not a span
input:read-only With readonly attribute p:only-of-type Unique of its parent
# CSS Fonts
Properties Shorthand
letter-spacing: <size>
# CSS Colors
Named color Hexadecimal color rgb() Colors
# CSS Backgrounds
Properties Shorthand
background: (Shorthand) background: #ff0 url(a.jpg) left top / 100px auto no-repeat fixed;
background-color: See: Colors background: #abc url(b.png) center center / cover repeat-x local;
left/center/right
background-position:
top/center/bottom
background-attachment: scroll/fixed/local
Properties Example
animation-duration: <time>ms
/* @keyframes duration | timing-function | delay | name */
animation: 3s linear 1s slidein;
ease / linear / ease-in / ease-
animation-timing-function:
out / ease-in-out
/* @keyframes duration | name */
animation-delay: <time>ms animation: 3s slidein;
# CSS Flexbox
Simple example - Container
.container { .container {
display: flex;
} display: flex;
display: inline-flex;
/* This: */
flex: 1 0 auto; align-items: flex-start; /* vertical-align to top */
align-items: flex-end; /* vertical-align to bottom */
/* Is equivalent to this: */ align-items: center; /* vertical-align to center */
flex-grow: 1; align-items: stretch; /* same height on all (default) */
flex-shrink: 0;
flex-basis: auto;
justify-content: flex-start; /* [xxx ] */
justify-content: center; /* [ xxx ] */
order: 1; justify-content: flex-end; /* [ xxx] */
justify-content: space-between; /* [x x x] */
align-self: flex-start; /* left */ justify-content: space-around; /* [ x x x ] */
justify-content: space-evenly; /* [ x x x ] */
margin-left: auto; /* right */
} }
.container {
display: flex; .container {
flex-direction: column; display: flex;
} }
CSS Block Level Grid - CSS grid-row CSS Inline Level Grid
Example
.item {
grid-row: 1 / span 2;
}
Example
#grid-container { #container {
display: grid; display: grid;
justify-items: start; align-items: start;
} grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 1fr;
.grid-items { grid-gap: 10px;
justify-self: end; }
}
/* Decrement "my-counter" by 1 */
Variable Usage ol {
counter-increment: my-counter -1;
counter-reset: section;
#firstParagraph { list-marker-type: none;
background-color: var(--first-color); /* Reset "my-counter" to 0 */ }
color: var(--second-color); counter-reset: my-counter;
} li::before {
counter-increment: section;
content: counters(section, ".") " ";
See also: CSS Variable See also: Counter set }
# Css 3 tricks
Scrollbar smooth
html {
scroll-behavior: smooth;
}
# Also see
CSS selectors cheatsheet (frontend30.com)
MDN: Using CSS flexbox
Ultimate flexbox cheatsheet
GRID: A simple visual cheatsheet
CSS Tricks: A Complete Guide to Grid
Browser support