build-your-own.org
BOOK
BLOG
SUBSCRIBE
build-your-own.org
prev ◄─┐
Contents
┌─► next
A Visual Guide To CSS
CHAPTER
Book info
CSS quick review
h1, h2 {
color: darkred;
font-style: italic;
} /* A comment. */
3
CSS
rule
syntax
Pt1. Language
CSS quick review
Comma-separated list of
selectors
`property-name: property-value` pairs
<h1>I’m red</h1>
<p>normal text.</p>
<h2>and italic</h2>
I’m red
normal text.
and italic
Simple CSS
selectors
Browser CSS +
your CSS
<div>
1
</div>
<div class="
item
">
2
</div>
<div class="
item
" id="
star
">
3
</div>
<div class="
item
special
">
4
</div>
div { color: red} /* select by
tag
name:
1, 2, 3, 4
*/
.item { color: red } /* select by
class
name:
2, 3, 4
*/
#star { color: red; } /* select by element
ID
:
3
*/
.item.special { color: red; } /* multiple class names:
4
*/
div.special { color: red; } /* tag name + class names:
4
*/
Table: diff
erent ways to apply a rule to elements.
Specifi
city
: resolving confl
icting
rules applied to one element.
Cascade and
specifi
city
Classes
and
IDs
enable CSS to select
specifi
c elements.
div { color: red; }
#star { color: green; }
.item { color: blue; }
.item { color: yellow; }
div { color: red; }
.item { color: blue; }
.item { color: yellow; }
#star {
color: green
;
}
sort
color: green;
cascade
more general
more specifi
c
(winner)
4
Pt1. Language
CSS quick review
Property inheritance
<div style="
color: darkred
; border: solid;">
I'm red. This div has a border.
<div>
I'm also red, but without a border.
</div>
<div style="
color: black
;">
Color overridden!
</div>
<div>
Properties related to
text formatting
are carried to descendants.
Canceling other rules
p { color: red; }
p.specific { color:
unset
; } /*
Remove
this property. */
p { color: red; }
p.specific { color:
revert
; } /* Use the browser's
default
. */
The eff
ect is not to set the property, which is
inheritance
for
inheritable properties, or to use the
initial value
for non-inheritables.
inheritable
non-inheritable
p { color: red; }
p.specific { color:
inherit
; } /*
Computed
value of the
parent
. */
Use special property values:
unset
,
revert
,
inherit
.
CSS = style + layout
●
Style is a
property
of an object,
such as font, color & border.
●
Style is
easier
because it's
confi
ned to a single object.
●
Style is often
cosmetic
; a
minimalist design is OK.
●
You can lookup stuff
on the fl
y.
●
Not much to say about style.
●
Layout is the
relationship
between
objects, like position & alignment.
●
Layout is
harder
because CSS deals
with properties, not relations.
●
Layout is
essential
; no design is OK
with objects in the wrong place.
●
Learning layout is the priority.
●
We'll focus on layout in this book.
(
Error report | Ask questions
)
@ build-your-own.org
A Visual Guide To CSS
prev ◄─┘
Contents
└─► next