Evans J. Hell Yes. CSS 2024
Evans J. Hell Yes. CSS 2024
Julia
Evans
V/hdts -this?
I wrote this zine because, after 15 years of being confused about
CSS, I realized I was still missing a lot of basic CSS knowledge.
Learning the facts in this zine helped me go from:
This zine also comes with i examples; for you to try out. They're at:
https://css-examples.wizardzines.com
Panels which have examples you can try are labelled fpA
table of contents
ATTiTudf LAYOUT GEfTTlMG FANCV
CSS isn't easy........................ H inline vs block.............12 hiding elements....... 20
CSS isn't design.................... 5 the box model............. 13 stacking contexts.... 21
CSS specifications................. 6 padding & margin.... IM CSS variables............22
backwards compatibility..... 7 borders...................... IS transitions................23
flexbox basics.......... 16
BASICS
CSS grid areas!....... 17 MAKING IT WOkK
selectors................................. 8
centering................... 18 media queries............2H
specificity.............................. .9 position: absolute....... ig the CSS inspector.......25
default stylesheets................10
testing checklist...... 26
units.........................................II
CSS seems simple and it is easy for but website layout is
at first simple tasks not an easy problem
h2 {
[Toe®-R* ^*" 1—
he cider
font-size: a layout this needs to
like this is
QI
ok this simple to aO many screen
is implement! sizes!
1 ~
how CSS
a selector with a selector with .classes a selector with an #id
element names loses to or :pseudoclasses loses to ,#header a {
body div span a .sidebar .link { / color: purple;
color: red; color: orange; J
'! important is very
hard to override,
loses to /an inline style loses to an !important rule* which makes life
( style="color: green;"J color: blue !important; hard for your
future self!
de4o<oW sA^esheets io
every browser has a different browsers you can read the
default stylesheet have different defaults default stylesheet
(aka "user agent stylesheet")
a small sample from the Firefox's default
Firefox default stylesheet: buttons t forms'^
stylesheets are at:
hi { have some of the
font-size: 2em; biggest differences resource://gre-resources/
font-weight: bold;
}
1
<div class="1">
<div class="2" /> __ 2
<div class="3" />
</div>
it <9
3. set grid-area
.top {grid-area: header}
.side {grid-area: sidebar}
.main {grid-area: content}
,+op
resuH ■'
. side . rnAi'n
Center incj
center text with center block elements margin: auto
text-align with margin: auto only centers horizontally
--------------------------------------------------------------------------------------- y tk>
vertical centering is easy with flexbox or grid%J^ it's ok to use a flexbox
here's how with grid: and with flexbox: or grid just to center
one thing
.parent { -Parent {
.paijent (display: grid)
display: grid; display: flex;
place-items: center; '
j .child {
margin: auto; /
} .child (centered!)
posi+ioH: absolute
position: absolute; top, bottom, left, right
doesn't mean absolutely positioned on the page: will place an absolutely
it's relative to the "containing block" positioned element
the "containing block" is Here's some typical CSS:
the closest ancestor with #square {
a position that isn't set position: absolute;
to static (the default top: 1em; left: 1em;
value), or the body if }
#parent { «-#parent
there's no such ancestor. position: relative;
(containing block)
-I
J this makes #parent the containing block.
transition has 3 parts not all property changes ...but there are dozens
can be animated.... of properties that can
transition: color 1s ease; list-style-type: square; if it's a number or color, it
can probably be animated!
/I don't know
which CSS . .. timing how to animate font-size: 14px;
properties durat'on
function that, sorry! rotate: 90deg;
to animate CS5
fenderer width: 20em;
medico queries 24
media queries let you max-width & min-width print and screen
use different CSS in @media (max-width: 500px) { screen is for computer/
different situations // CSS for small screens mobile screens
@media media } print is used when
/^footer c~ query printing a webpage
@media (min-width: 950px) {
display: none A
// CSS for large screens there are more: tv, tty,
____
} speech, braille, etc
} CSS to apply
different browsers
have different tools!
For example, Firefox
has special tools for
debugging grid/flexbox
res-kina checklist m>
Finally, it's important to test your site with different browsers, screen
sizes, and accessibility evaluation tools.
browsers sizes accessibility
□ Chrome □ small phone (300px wide) □ colour contrast
Hundreds of helpful blog posts and Tells you which browser versions (and
incredible guides, like their guides what likely % of your users) have
to centering & flexbox. support for each CSS feature.
<7V/3 (w3.org/TR/CSS)
Mozilla Developer Network
(developer.mozilla.org)
The CSS specifications. Can be
My favourite reference for useful as a reference too!
CSS, JS, HTML, and HTTP
____________ [credits
Cover art: Vladimir Kasikovic ‘ ■
Editing: Dolly Lanuza, Kamal Marhubi
Technical review: Melody Starling
and thanks to all the beta readers V
V -VhiS?
more ocV
★ v/izardzinescom <