Cascading Style Sheet
Cascading Style Sheet
Agenda
What is CSS? Syntax Applying CSS Commonly used CSS properties Grouping and Nesting Floats in Page Layouting @ rules !A
Syntax
A style sheet consists o+ a list o+#rules( -ach rule or rule.set consists o+ one or more#selectors" and a#declaration block(
selector [, selector2, ...] [:pseudo-class] { property: value; [property2: value2; ...] } /* comment */
Applying CSS
&here are three $ays to apply CSS to %&'L/# In-line# $ritten directly inside the tag
0p style12color/ red23text04p3
%&'L
0lin, rel12stylesheet2 href12style(css23
selector
property
#nits
General 9nits used in *alues/ px#:such as#font-size/ ;<px= is the unit +or pixels( em#:such as#font-size/ <em= is the unit +or the calculated si>e o+ a +ont( So ?<em@" +or example" is t$o times the current +ont si>e( pt#:such as#font-size/ ;<pt= is the unit +or points" typically used in printed media( A#:such as#width/ BCA= Dther units include pc:picas=" cm" mm and in:inches= Note/ When a *alue is#zero" there is no need to state a unit( For e(g( to speci+y no )order" it $ould )e#border/ C(
Colors
Colors in CSS can ta,e the +orm o+/
name .#E.g.: color/red EGF *alue G E.g.: color/ rg):<HH"C"C= EGFA *alue . E.g.: color/ rg)a:<HH"C"C";= %exa *alue . E.g.: color/ I++CCCC or color/I+CC %SL *alue . E.g.: color/ hsl:C";CCA"HCA= %SLA *alue . E.g.: color/ hsla:C";CCA"HCA"C(J=
Colors - $radients
Gradients lets you display smooth transitions )et$een t$o or more speci+ied colors Fro$sers support t$o types o+ gradients . linear and radial Linear Gradient background/ linear.gradient:to )ottom right" )lue" $hite=6 background/ linear.gradient:KCdeg" )lac," $hite=6 background/ linear.gradient:to )ottom" )lue" $hite BCA" orange=6 background/ linear.gradient:to right" rg)a:<HH"<HH"<HH"C=" rg)a:<HH"<HH"<HH";==" url:http/44+oo(com4image(Lpg=6
)ext
&ext in CSS can )e manipulated using the +ollo$ing properties/ +amily .#E.g.: font-family/ Arial" %el*etica" sans.seri+ si>e G E.g.: font-size/;Opx style . E.g.: font-style/italic6 (normal, italic, oblique, inherit) $eight . E.g.: font-weight/)old6 (normal, bold, bolder, lighter, !!"
#!!, inherit)
*ariant . E.g.: font-$ariant/small.caps6 (normal, inherit) All in one order G ?0+ont.style30 +ont.*ariant 30+ont.$eight30
+ont.si>e4line.height30 +ont.+amily3@ E.g.: font/ italic )old ;<px4JCpx Georgia" seri+6 Dther &ext properties that can )e re+erred to G %e&t-decoration, te&t-transform, letter-spacing, word-spacing, lineheight, te&t-align, te&t-indent etcP
*ac+ground
Fac,grounds are a core part o+ CSS" that can )e used to add color or images to a page or element( Qt can )e manipulated using the +ollo$ing properties/ )ac,ground.color .#E.g.: background-color /rg)a:C"C"<HH";= )ac,ground.image G E.g.: background-image/ url:image(Lpg=6 )ac,ground.position . E.g.: background-position/ KHpx C6 (left,
center, right, top, center, bottom)
S,ado-s
Fox.shado$ allo$s casting a drop shado$ +rom the +rame o+ almost any element( Qt ta,es the +orm as )elo$/ bo&-shadow/ none R inset 0o++set.x3 0o++set.y3 0)lur.radius3 0spread.radius3 0color3
(shado$ 5 bo&-shadow/ Npx Npx Npx Hpx I+CC6 7
*orders
9sed to set )orders around an element( &he properties that can )e set are Width . E.g.: border-width/ ;<px6 Style . E.g.: border-style: solid; (none, hidden, dotted, dashed, solid, double
groove, ridge, inset, outset, inherit)
$rouping
$rouping is giving t,e sa6e properties to a nu65er o0 selectors -it,out ,aving to repeat t,e6. <ou can si6ply separate selectors -it, co66as in one line and apply t,e sa6e properties to all o0 t,e6.
h< 5 color: red6 7 (secondClass 5 color: red6 7 (thirdClass 5 color: red6 7 h<" (secondClass" (thirdClass 5 color: red6 7
>esting
>esting is speci0ying properties to selectors -it,in ot,er selectors. ),is re6oves t,e need 0or classes or 34s on t,e p and ,? tags i0 it is applied to 8).9 t,at loo+s so6et,ing li+e t,is:
0di* id12top23 0h;3Sport04h;3 0p3Sport#re+ers to a#competiti*e#physical acti*ity(04p3 0p32Sport2 comes +rom the#Dld French#desport#meaning 2leisure?(04p3 04di*3
CSS
Itop 5 background-color: Iccc6 padding: ;em6 7 Itop h; 5 color: I++C6 7 Itop p 5 color: red6 font-weight: )old6 7
@utput:
Sport Sport#re+ers to a#competiti*e#physical acti*ity( ?Sport@ comes +rom the#Dld French#desport#meaning ?leisure@(
seudo Classes
Pseudo classes#are added to selectors to speci+y a state or relation to the selector( &hey are $ritten simply $ith a colon in )et$een the selector and the pseudo class( #
Dther pseudo classes that can )e re+erred to are first-child, last-child, focus, first-letter, before, after etc"
Clearing Aloats
Aloats -,en used need to 5e cleared and t,at is done using t,e clear property E.g.: clear:5ot,;
Float cleared
At- Bules
At.rules are cle*er" po$er+ul little huggers that encapsulate a )unch o+ CSS rules and apply them to something speci+ic( &hey can )e used to import other CSS +iles" apply CSS to a particular#media" or em)ed uncommon fonts(
Qmporting
'import#rule is used to )olt another stylesheet onto your existing one( &his#must#)e placed at the top o+ a stylesheet" )e+ore any other rules( -(g(/ 'import url:morestyles(css=6
Cnd
&han, Uou V