Lukáš Bařinka
CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.
<html>
<head>
<title>Plain HTML</title>
</head>
<body>
<h1>Page Headline</h1>
<p>Summary paragraph</p>
<p class="motto">Motto paragraph</p>
<p id="p123">Normal text paragraph</p>
</body>
</html>
<html>
<head>
<title>Linked CSS</title>
<link rel="stylesheet" type="text/css"
href="http://style.com/cool" title="cool">
</head>
<body>
<h1>Page Headline</h1>
<p>Summary paragraph</p>
<p class="motto">Motto paragraph</p>
<p id="p123">Normal text paragraph</p>
</body>
</html>
<html>
<head>
<title>Imported CSS</title>
<style type="text/css">
@import url("http://style.com/basic");
</style>
</head>
<body>
<h1>Page Headline</h1>
<p>Summary paragraph</p>
<p class="motto">Motto paragraph</p>
<p id="p123">Normal text paragraph</p>
</body>
</html>
<html>
<head>
<title>Included CSS</title>
<style type="text/css">
h1 { color: blue }
p.motto { color: yellow }
#p123 { color: green }
</style>
</head>
<body>
<h1>Page Headline</h1>
<p>Summary paragraph</p>
<p class="motto">Motto paragraph</p>
<p id="p123">Normal text paragraph</p>
</body>
</html>
<html>
<head>
<title>Inline CSS</title>
</head>
<body>
<h1>Page Headline</h1>
<p style="color: red">Summary paragraph</p>
<p class="motto">Motto paragraph</p>
<p id="p123">Normal text paragraph</p>
</body>
</html>
<html>
<head>
<title>Inline CSS</title>
<link rel="stylesheet" type="text/css"
href="http://style.com/cool" title="cool">
<style type="text/css">
@import url("http://style.com/basic");
h1 { color: blue }
.motto { color: yellow }
#p123 { color: green }
</style>
</head>
<body>
<h1>Page Headline</h1>
<p style="color: red">Summary paragraph</p>
<p class="motto">Motto paragraph</p>
<p id="p123">Normal text paragraph</p>
</body>
</html>
red
) Vs. Strings ("red"
){ }
;
/* */
<!-- -->
allowed, but do not delimit CSS comment)@charset "ISO-8859-2"
h1 { color: red }
h2 { color: red }
h1, h2 { color: red }
h1 { font-size: 12pt }
h1 { font-weight: bold }
h1 { font-family: "Helvetica" }
h1 { font: bold 12pt "Helvetica" }
em
- font sizerem
- root element font sizeex
- height of letter "x"%
- of parent valuevw/vh/vmin/vmax
- 1% of viewport width/heightpx
- pixel / visual angle unit (1/96 in)in, cm, mm
pt
- typographical point (1/72 in)pc
- pica (12 pt)url("img.jpg")
url("https://example.com/file")
local("Gentium Bold")
red
#f00
#ff0000
rgb(), rgba(), hsl(), hsla()
"Helvetica"
serif
sans-serif
monospace
cursive
fantasy
rgb(255,0,0) / rgb(100%,0%,0%) / rgba()
hsl() / hsla()
url()
calc(50% - 2em)
attr(href)
counter(h)
E | Type |
E F | Descendant |
.class | Class |
#id | ID |
:link | Link history pseudo-class |
:active | User action pseudo-class |
* | Universal |
E > F | Child |
E + F | Adjacent sibling |
:first-child | Structural pseudo-element |
:hover | User action pseudo-class |
:lang(en) | Lang pseudo-class |
[attribute] | Attribute |
:first-child
:first-line, :first-letter
:before, :after
:link, :visited
:hover, :focus
@page :first
@page :left, :right
E ~ F
:target
:root, :empty
:last-child, :last-of-type
:nth-child(n), nth-of-type(n)
:nth-last-child(n), nth-last-of-type(n)
:only-child, :only-of-type
:enabled, :disabled, :checked
:not(s)
[attr] | Any value |
[attr="val"] | Exact value |
[attr~="val"] | Exact value in space-separated list |
[attr|="val"] | Beginning value in hyphen-separated list e.g. "en-US" |
[attr^="val"] | Begins with |
[attr$="val"] | Ends with |
[attr*="val"] | Contains substring |
Some values are inherited, some values don't
body {
color: black; /* value inherits */
background: white; /* value does not inherit */
}
p {
background: inherit; /* 'inherit' value */
}
[hidden] {
display: none !important;
}
a | style atribute |
b | ID atribute count |
c | others atribute and pseudo-class count |
d | pseudo-/element's name count |
a → b → c → d
* /* a=0 b=0 c=0 d=0 */
li /* a=0 b=0 c=0 d=1 */
li:first-line /* a=0 b=0 c=0 d=2 */
ul li /* a=0 b=0 c=0 d=2 */
ul li+li /* a=0 b=0 c=0 d=3 */
h1 + *[rel=up] /* a=0 b=0 c=1 d=1 */
ul ol li.red /* a=0 b=0 c=1 d=3 */
li.red.level /* a=0 b=0 c=2 d=1 */
#x34y /* a=0 b=1 c=0 d=0 */
style="" /* a=1 b=0 c=0 d=0 */
1. Declared value | Filtered values from rules |
2. Cascaded value | Winning value of cascade |
3. Specified value | Winning or defaul value |
4. Computed value | Absolute value (inherit) |
5. Used value | Real values (e.g. auto) |
6. Actual value | Adjust value (e.g. round) |
• initial
• inherit
• unset
all: initial | inherit | unset
border-width
border-color
border-style
border
h1 { border: thin solid sliver }
color:
background-color:
background:
background-image:
background-repeat:
background-attachment:
background-position:
background-image: url(flower.png), url(ball.png), url(grass.png);
background-position: center center, 20% 80%, top left, bottom right;
background-origin: border-box, content-box;
background-repeat: no-repeat;
background-clip:
background-origin:
background-size:
box-shadow:
width: 100px; height: 100px;
border: 12px solid blue; background-color: orange;
border-top-left-radius: 60px 90px;
border-bottom-right-radius: 60px 90px;
box-shadow: 64px 64px 12px 40px rgba(0,0,0,0.4),
12px 12px 0px 8px rgba(0,0,0,0.4) inset;
border-radius:
border-image-source:
border-image-slice:
border-image-width:
border-image-outset:
border-image-repeat:
block
inline-block
inline
list-item
none
table
inline-table
table-row-group
table-column
table-column-group
table-header-group
table-footer-group
table-row
table-cell
table-caption
position: static
position: relative
position: absolute
position: fixed
float: ...
clear: ...
position ≠ static
top | right | bottom | left:
float:
clear:
z-index:
visibility:
overflow:
clip:
inline
elements,width:
min-width:
max-width:
inline
elements,height:
min-height:
max-height:
line-height:
vertical-align:
text-align:
text-align-last:
text-indent:
text-decoration
letter-spacing:
word-spacing:
white-space
normal
= ✓ WS, ✓ wrappre
= ✗ WS, ✗ wrap, ✓ NLnowrap
= ✓ WS, ✗ wrappre-wrap
= ✗ WS, ✓ wrap, ✓ NLpre-line
= ✓ WS, ✓ wrap, ✓ NLtext-transform:
font-family:
font-style:
font-variant:
font-weight:
font-size:
font:
p { font: 12px/14px sans-serif }
p { font: 80% sans-serif }
p { font: x-large/110% "New Century Schoolbook", serif }
p { font: bold italic large Palatino, serif }
p { font: normal small-caps 120%/120% fantasy }
@font-face {
}
word-break:
line-break:
hyphens:
content
property of
:before
pseudo-elements:after
pseudo-elementsdisplay: list-item
p.note:before { content: "Note: " } /* \A = line break */
none | not generated |
normal | 'none' for :before/:after |
string | text content |
uri | external resource (e.g. image) |
counter | counter content |
open-quote | string from 'quotes' property |
no-open-quote | no content, changes level of nesting |
attr() | string value of attribute |
quotes:
q:lang(no) { quotes: "«" "»" '"' '"' }
q:before { content: open-quote }
q:after { content: close-quote }
<p><q>Trøndere gråter når <q>Vinsjan på kaia</q> blir deklamert.</q>
«Trøndere gråter når "Vinsjan på kaia" blir deklamert.»
counter-reset:
counter-increment:
body { counter-reset: chapter; }
h1:before {
content: "Chapter " counter(chapter) ". ";
counter-increment: chapter;
}
h1 { counter-reset: section; }
h2:before {
content: counter(chapter) "." counter(section) " ";
counter-increment: section;
}
ol { counter-reset: item }
li { display: block }
li:before { content: counters(item, ".") " "; counter-increment: item }
counter(name)
counter(name list-style-type)
list-style-type:
list-style-image:
list-style-position:
list-style:
<link rel="stylesheet" type="text/css" media="screen" href="style.css">
<link rel="stylesheet" type="text/css" media="print" href="print.css">
@media screen {
* { font-family: sans-serif }
}
@import "print-styles.css" print;
<link media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css">
<link media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css" />
<?xml-stylesheet media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css" ?>
@import url(example.css) screen and (color), projection and (color);
@media screen and (color), projection and (color) { … }
@media media-list { rule-set }
all | all devices |
screen | color computer screen |
print | paged media/print preview |
braille | braille tactile feedback devices |
embossed | paged braille printer |
handheld | typically small screen, limited bandwidth |
projection | presentation, paged media |
speech | speech synthesizer |
tty | fixed-pitch character grid (no px) |
tv | typically low resolution, color, limited-scrollability, audio |
min-*
= greater or equalmax-*
= smaller or equalwidth, device-width
height, device-height
orientation
aspect-ratio, device-aspect-ratio
16/9
)color, color-index, monochrome
resolution
300dpi, 118dpcm
)grid
overflow-block
overflow-inline
(any-)pointer
= any/primary device(any-)hover
= any/primary device, | media-type , media-type |
and | media-type and (media-feature) |
not | not media-type |
only | only media-type |
columns
column-width
column-count
column-gap
column-rule
column-span
column-fill
display:
flex-direction:
flex-wrap:
display:
grid-template-rows:
grid-template-columns:
grid-column:
grid-row:
grid-template-areas:
grid-area: