- MDN CSS
- http://cssreference.io
- http://htmlreference.io
- http://bulma.io
- http://cssgridgarden.com
- http://flexboxfroggy.com/
External link
(good DRY way):
<head>
<link rel="stylesheet" href="styles.css" />
</head>
In the head
:
<head>
<style>
h1 {color: red; }
</style
</head>
Inline style
attribute: <h1 style="color: red;">Learning CSS</h1>
- External
link
- In the
head
- Inline
style
attribute - Using
!important
(exbackground: #e0e2e6 !important;
)
If we have same selectors:
.intro {
width: 900px;
color: black;
}
.intro {
color: red; /* last definition overrides previous */
margin-bottom: 5px; /* non-conflicting properties will be combined */
}
Result:
width: 900px;
color: red;
margin-bottom: 5px;
Sample: <h1 id="main" class="article home"></h1>
element h1 { ... }
class .article { ... }
ID #main { ... }
combined h1#main.article.home { ... }
grouping h1, h2, p { ... }
universal selector *
: *.warning
and .warning
are equal
Attribute selector:
[attr]
[attr=value]
span[lang~="en-us"]
<span lang="en-us en-gb en-au en-nz">
span[lang|="zh"]
<span lang="zh-CN">世界您好</span>
a[href^="#"]
all internal linksa[href$=".cn"]
<a href="http://example.cn">Chinese</a>
a[href*="example"]
all links to with "example" in the url
Combinations:
- adjacent sibling
li:first-of-type + li
- general sibling
p ~ span
- direct children
div > span
- descendant
div span
matches<div><p><span>...</span></p></div>
Pseudo-elements: ::after
, ::before
, ::first-letter
, ::first-line
, ::selection
Pseudo-classes:
- a
:link
,:visited
,:hover
,:active
:not
ex:div:not(.outer)
@charset
, @import
, @media
, @supports
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Counters
float: left | right | none
visibility: hidden
display: inline | block | none | ...
content - padding - border - margin
width
,height
,padding
,border
,margin
,outline
overflow
position:
static
- by default - normal flow of the pagefixed
- positioned relative to the browser windowrelative
to its normal positionabsolute
relative to the first parent element that has a position other than static
top
,bottom
,left
,right
float: right | left
clear: none | left | right | both