This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from jmhorak/css-overview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
3058 lines (2880 loc) · 113 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--
Google HTML5 slide template
Authors: Luke Mah (code)
Marcin Wichary (code and design)
Dominic Mazzoni (browser compatibility)
Charles Chen (ChromeVox support)
URL: http://code.google.com/p/html5slides/
-->
<!--
Become a CSS Pro
Author: Jeff Horak
July 2012
URL: http://jmhorak.github.com/css-overview
-->
<html xmlns="http://www.w3.org/1999/html">
<head>
<title>Become a CSS Pro</title>
<meta charset='utf-8'>
<script
src='http://html5slides.googlecode.com/svn/trunk/slides.js'></script>
<link href='http://fonts.googleapis.com/css?family=IM+Fell+English+SC' rel='stylesheet' type='text/css'>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33662740-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<style>
/* Your individual styles here, or just use inline styles if that's
what you want. */
ul.tree li {
margin-bottom: 0;
}
.noWrapping {
white-space: nowrap;
}
div.button {
padding: 3px 11px;
margin: 3px 5px;
background-image: -webkit-linear-gradient(top, whitesmoke, lightgray);
background-image: -moz-linear-gradient(top, whitesmoke, lightgray);
background-image: -ms-linear-gradient(top, whitesmoke, lightgray);
background-image: -o-linear-gradient(top, whitesmoke, lightgray);
background-image: linear-gradient(top, whitesmoke, lightgray);
border: 1px solid gray;
border-radius: 4px;
cursor: default;
box-shadow: 0 1px 1px #202020;
margin: 40px auto;
width: 125px;
text-align: center;
}
div.button:active {
background-image: -webkit-linear-gradient(top, lightgray, whitesmoke);
background-image: -moz-linear-gradient(top, lightgray, whitesmoke);
background-image: -ms-linear-gradient(top, lightgray, whitesmoke);
background-image: -o-linear-gradient(top, lightgray, whitesmoke);
background-image: linear-gradient(top, lightgray, whitesmoke);
box-shadow: inset 1px 1px 4px #202020;
}
div.button:hover {
color: orangered;
}
article.smaller div:not(.source) {
font-size: 20px;
line-height: 24px;
letter-spacing: 0;
}
.fell-English {
font-family: 'IM Fell English SC', serif;
text-rendering: optimizeLegibility;
letter-spacing: 2px;
}
.exampleSpacing {
margin-top: 20px;
}
.text-demo-box {
height: 80px;
width: 120px;
background-color: yellow;
border: 3px solid orange;
font-size: 20px;
}
.segue {
background-image: -webkit-linear-gradient(bottom, lightgray, white 50%);
background-image: -moz-linear-gradient(bottom, lightgray, white 50%);
background-image: -ms-linear-gradient(bottom, lightgray, white 50%);
background-image: -o-linear-gradient(bottom, lightgray, white 50%);
background-image: linear-gradient(bottom, lightgray, white 50%);
}
.colorSegue {
background-image: -webkit-linear-gradient(top, greenyellow, green);
background-image: -moz-linear-gradient(top, greenyellow, green);
background-image: -ms-linear-gradient(top, greenyellow, green);
background-image: -o-linear-gradient(top, greenyellow, green);
background-image: linear-gradient(top, greenyellow, green);
}
.colorTitle {
background-color: rgba(255, 255, 255, 0.2);
text-shadow: 3px 1px 4px #202020;
width: 100%;
right: 0;
text-indent: 40px;
padding-right: 0;
}
.collapseMargin {
margin-top: 20px;
margin-bottom: 10px;
outline: 1px solid red;
}
.box {
border: 3px solid gray;
}
.box1 {
background-color: yellow;
border-color: orangered;
}
.box2 {
background-color: lightblue;
}
.box3 {
background-color: #90ee90;
border-color: green;
}
.box-container {
outline: 1px dashed gray;
}
.bfcDiv {
background-color: orangered;
}
.bfcP {
margin: 20px 0;
background-color: yellow;
}
.bfc-floated-p {
padding: 20px; float: left;
}
.bfc-floated-parent-div {
background-color: lightblue;
}
#performanceResults {
width: 778px;
height: 300px;
}
#performanceDataTable {
font-size: 16px;
line-height: 1.1em;
}
</style>
<body style='display: none'>
<section class='slides layout-regular'>
<!-- Title -->
<article class="segue">
<h1>
Become a CSS Pro
</h1>
<p>Jeff Horak<br>July 5, 2012</p>
<p>Slides:
<a href="http://jmhorak.github.com/css-overview">
http://jmhorak.github.com/css-overview
</a>
</p>
</article>
<!-- Agenda -->
<article>
<h3>
Agenda
</h3>
<ul>
<li>Getting Started</li>
<li>Browser Basics and Tooling</li>
<li>Selectors</li>
<li>Units of Measurement</li>
<li>Layouts</li>
<li>Colors, Shadows, and Gradients</li>
<li>Working with Text</li>
<li>The Story on Vendor Prefixes</li>
<li>SASS</li>
<li>CSS Performance</li>
</ul>
</article>
<!-- Segue to Getting Started -->
<article class="segue">
<h2>Getting Started</h2>
</article>
<!-- Slide Format -->
<article>
<h3>Slide Format</h3>
<p>
All slides were created using <a href="http://code.google.com/p/html5slides/">html5slides</a>.
</p>
<p>
CSS examples are running live - there are no images.
</p>
<div class="source">
A source, citation, or link to further reading provided in this space.
</div>
</article>
<!-- Search like a Pro -->
<article>
<h3>Searching like a Pro</h3>
<p>
Not everyone know everything. Sometimes you need to look at an API.
</p>
<p>
Most of the time, the first hit when searching for any JavaScript/HTML/CSS subject is w3schools.
</p>
<p>
<a href="http://w3fools.com/">W3Schools is bad news</a>. They are a for-profit not in
any way affiliated with the W3C standards body.
</p>
<p>
Their published content is inaccurate and misleading.
</p>
<div class="source">
Further Reading: <a href="http://w3fools.com/">W3Fools</a>
</div>
</article>
<!-- MDN -->
<article>
<h3>W3Schools Alternatives</h3>
<img style="float: left; margin-top: 20px; margin-right: 10px;" src="img/mdn.png">
<p>
The <a href="https://developer.mozilla.org">Mozilla Developer Network</a> is a
comprehensive source of documentation for JavaScript/HTML/CSS/XML/SVG and more.
</p>
<p>
Prefix any search with "MDN" to get the Mozilla Developer page as the first hit.
</p>
<pre>
MDN vertical-align</pre>
</article>
<!-- Segue to Browser Basics -->
<article class="segue">
<h2>Browser Basics</h2>
</article>
<!-- How It Works -->
<article>
<h3>
How It Works
</h3>
<p>
After any page is loaded, browsers immediately start parsing HTML elements.
</p>
<ul>
<li>Scripts encountered are executed immediately</li>
<li>Mark-up is parsed and organized into the DOM Tree</li>
<li>CSS is parsed into buckets based on the selector</li>
</ul>
</article>
<!-- DOM and Render Trees -->
<article class='smaller'>
<h3>DOM and Render Trees</h3>
<p>
The DOM tree is the result of parsing the HTML that comes back from the network layer.
</p>
<p>
The DOM Tree is combined with the CSS to form the render tree. This is ultimately what is painted on-screen.
</p>
<p>
There is a 1:1 relationship between HTML elements and DOM elements. There is not a 1:1 relationship between DOM elements and render elements.
</p>
<div style='margin-top: 20px; display: inline-block; vertical-align: top'>
DOM tree
<ul class='tree'>
<li>
html
<ul>
<li>
head
<ul>
<li>title</li>
<li>style</li>
</ul>
</li>
<li>
body
<ul>
<li>h1</li>
<li>
div
<ul>
<li>span</li>
<li>img</li>
<li>a</li>
</ul>
</li>
<li>
div
<ul>
<li>text block</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div style="margin: 20px 70px; display: inline-block; vertical-align: top">
CSS
<code style="display: block; font-size: 20px;">span { display: none; }</code>
</div>
<div style="margin-top: 20px; display: inline-block; vertical-align: top">
Render tree
<ul class='tree'>
<li>
viewport
<ul>
<li>
scrolling area
<ul>
<li>h1 block</li>
<li>
div block
<ul>
<li>img block</li>
<li>a text block</li>
</ul>
</li>
<li>
div block
<ul>
<li>
text line
<ul>
<li>text block</li>
</ul>
</li>
<li>
text line
<ul>
<li>text block</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</article>
<!-- Painting Flow -->
<article>
<h3>Painting</h3>
<img style="height: 66px; width: 600px; margin: 30px auto; display: block;" src='img/flow.png'>
<q style="font-size: 1em; line-height: 45px; margin-left: 75px; margin-right: 75px; margin-top: 0;">
For better user experience, the rendering engine will try to display contents on the screen as soon as possible. It will not wait until all HTML is parsed before starting to build and layout the render tree. Parts of the content will be parsed and displayed, while the process continues with the rest of the contents that keeps coming from the network.
</q>
<div class="source">Source: <a href="http://www.html5rocks.com/en/tutorials/internals/howbrowserswork">How Browsers Work</a></div>
</article>
<!-- Rendering Engine Order -->
<article>
<h3>Painting</h3>
<p>
The rendering engine paints the render tree elements in order based on the stacking context.
</p>
<p>
The stacking context encapsulates z-index, element flow, and position within the mark-up.
</p>
<p>
The stacking order within a context for a block renderer is:
</p>
<ul>
<li>background color</li>
<li>background image</li>
<li>border</li>
<li>children</li>
<li>outline</li>
</ul>
<div class="source">Source: <a href="http://www.html5rocks.com/en/tutorials/internals/howbrowserswork">How Browsers Work</a>, <a href="http://www.w3.org/TR/CSS21/zindex.html">W3C - Stacking contexts</a></div>
</article>
<!-- Desktop Tools for Debugging CSS -->
<article>
<h3>Tools for Debugging CSS</h3>
<p>All desktop browsers have built in developer tools.</p>
<p>Debugging CSS issues is more effectively done within those developer tools.</p>
<p style='color: #c34daa;'>Individual CSS rules may be toggled</p>
<p>Rules and classes may also be added</p>
<p>Element states may be set to debug more interesting cases</p>
<div class="button">
Push Me
</div>
</article>
<!-- Firefox 3D Render View -->
<article class='fill'>
<h3>Firefox 3D render view</h3>
<img src="img/firefox3d.png">
</article>
<!-- Segue to Selectors -->
<article class="segue">
<h2>Selectors</h2>
</article>
<!-- Basic Selector Primitives -->
<article>
<h3>Basic Selector Primitives</h3>
<p>Shorthand language for matching CSS rules to DOM elements</p>
<p>Some basic examples:</p>
<table>
<thead>
<tr>
<th>
Selector
</th>
<th>
Category
</th>
<th>
Matched elements
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="noWrapping"><code>.myClass</code></td>
<td>Class</td>
<td>Match element with class <code>myClass</code></td>
</tr>
<tr>
<td class="noWrapping"><code>#myID</code></td>
<td>ID</td>
<td>Match element with ID <code>myID</code></td>
</tr>
<tr>
<td class="noWrapping"><code>span</code></td>
<td>Tag</td>
<td>Match all <code>span</code>s</td>
</tr>
<tr>
<td class="noWrapping"><code>*</code></td>
<td>Universal</td>
<td>Match all elements</td>
</tr>
</tbody>
</table>
<p style="font-size: 0.7em">
Rules are divided into categories based on the right-most portion of the selector.<br>More
on this later.
</p>
<div class="source">
Further Reading: <a href="https://developer.mozilla.org/En/CSS/Class_selectors">Class selectors</a>,
<a href="https://developer.mozilla.org/En/CSS/ID_selectors">ID selectors</a>,
<a href="https://developer.mozilla.org/en/CSS/Type_selectors">Type selectors</a>,
<a href="https://developer.mozilla.org/en/CSS/Universal_selectors">Universal selector</a>
</div>
</article>
<!-- Combining Primitives -->
<article>
<h3>Combining Primitives</h3>
<table>
<thead>
<tr>
<th>Selector</th>
<th>Matched elements</th>
</tr>
</thead>
<tbody>
<tr>
<td class="noWrapping"><code>div.myClass</code></td>
<td>All <code>div</code>s with the class <code>myClass</code></td>
</tr>
<tr>
<td class="noWrapping"><code>div.myClass,<br>a#myID,<br>span</code></td>
<td>All <code>div</code>s with the class <code>myClass</code> AND<br>the <code>a</code> with ID <code>myID</code> AND<br>all <code>span</code>s</td>
</tr>
<tr>
<td class="noWrapping"><code>div .myClass</code></td>
<td>Any element with class <code>myClass</code> which has an ancestor that is a <code>div</code></td>
</tr>
<tr>
<td class="noWrapping"><code>div > .myClass</code></td>
<td>Any element with class <code>myClass</code> whose parent is a <code>div</code></td>
</tr>
<tr>
<td class="noWrapping"><code>div + .myClass</code></td>
<td>Any element with class <code>myClass</code> that is immediately preceded by a <code>div</code></td>
</tr>
</tbody>
</table>
<div class="source">
Further Reading: <a href="https://developer.mozilla.org/en/CSS/Child_selectors">Child selectors</a>,
<a href="https://developer.mozilla.org/en/CSS/Descendant_selectors">Descendant selectors</a>
</div>
</article>
<!-- Attribute Selectors -->
<article>
<h3>Attribute Selectors</h3>
<table>
<thead>
<tr>
<th>Selector</th>
<th>Matched elements</th>
</tr>
</thead>
<tbody>
<tr>
<td class="noWrapping"><code>input[checked]</code></td>
<td>All checked <code>input</code>s</td>
</tr>
<tr>
<td class="noWrapping"><code>input[type='text']</code></td>
<td>All line edits</td>
</tr>
</tbody>
</table>
<div class="source">
Further Reading: <a href="https://developer.mozilla.org/en/CSS/Attribute_selectors">Attribute Selectors</a>
</div>
</article>
<!-- Pseudo Classes -->
<article>
<h3>Pseudo Classes</h3>
<p>CSS allows matching to special states of elements.</p>
<table>
<thead>
<tr>
<th>Selector</th>
<th>Matched elements</th>
</tr>
</thead>
<tbody>
<tr>
<td class="noWrapping"><code>a:link</code></td>
<td>All unvisited links</td>
</tr>
<tr>
<td class="noWrapping"><code>a:visited</code></td>
<td>All visited links</td>
</tr>
<tr>
<td class="noWrapping"><code>a:active</code></td>
<td>Matches a link that is being clicked on</td>
</tr>
<tr>
<td class="noWrapping"><code>*:focus</code></td>
<td>Matches the elements with the current focus</td>
</tr>
<tr>
<td class="noWrapping"><code>.myClass:hover</code></td>
<td>Matches when hovering over an element with class <code>myClass</code></td>
</tr>
</tbody>
</table>
<div class="source">
Further Reading: <a href="https://developer.mozilla.org/en/CSS/Pseudo-classes">Pseudo-Classes</a>
</div>
</article>
<!-- More Pseudo Classes -->
<article class="smaller">
<h3>More Pseudo Classes</h3>
<p>These selectors match elements very specific placement within the DOM</p>
<table>
<thead>
<tr>
<th>Selector</th>
<th>Matched elements</th>
</tr>
</thead>
<tbody>
<tr>
<td class="noWrapping"><code>li:first-child</code></td>
<td>Matches the first list item under the parent</td>
</tr>
<tr>
<td class="noWrapping"><code>div:nth-child(<em>a</em>n + <em>b</em>)</code></td>
<td>Matches <code>div</code>s that are <em>b</em>th child of the parent after all its children have been split into groups of <em>a</em> elements each.</td>
</tr>
<tr>
<td class="noWrapping"><code>span:nth-of-type(<em>a</em>n + <em>b</em>)</code></td>
<td>Similar to nth-child except the groups only contain <code>span</code>s</td>
</tr>
<tr>
<td class="noWrapping"><code>.myClass:empty</code></td>
<td>Matches elements with class <code>myClass</code> without any children<br><strong>Note:</strong> text (including whitespace) are considered children</td>
</tr>
<tr>
<td class="noWrapping"><code>input:enabled</code></td>
<td>Matches all enabled <code>input</code> fields</td>
</tr>
<tr>
<td class="noWrapping"><code>input:disabled</code></td>
<td>Matches all disabled <code>input</code> fields</td>
</tr>
<tr>
<td class="noWrapping"><code>span:not(.myClass)</code></td>
<td>Matches all <code>span</code>s without class <code>myClass</code></td>
</tr>
</tbody>
</table>
<div class="source">
Further Reading: <a href="https://developer.mozilla.org/en/CSS/Pseudo-classes">Pseudo-Classes</a>,
<a href="https://developer.mozilla.org/en/CSS/%3Anth-child">:nth-child</a>,
<a href="https://developer.mozilla.org/en/CSS/%3Anth-of-type">:nth-of-type</a>,
<a href="https://developer.mozilla.org/en/CSS/%3Aempty">:empty</a>,
<a href="https://developer.mozilla.org/en/CSS/%3Anot">:not</a>
</div>
</article>
<!-- Conflicting Styles -->
<article>
<h3>How Are Conflicting Styles Resolved?</h3>
<p>The rendering engine may have multiple styles it needs to apply to a particular element.</p>
<pre>div { background-color: green; }
div { background-color: gray; }</pre>
<div style="height: 100px; width: 600px; margin: 40px auto; position: relative">
<div style="width: 300px; height: 100%; background-color: green; display: inline-block;">
</div><div style="width: 300px; height: 100%; background-color: gray; display: inline-block;"></div>
<div style="position: absolute; left: 50%; top: 50%; margin-left: -267px; margin-top: -18px; color: black;">
Should the background be <span style="color: #adff2f;">green</span> or <span style="color: lightgray;">gray</span>?
</div>
</div>
</article>
<!-- Resolution Characteristics -->
<article>
<h3>Resolution Characteristics</h3>
<p>
Resolving conflicts requires looking at several pieces of information
</p>
<ul>
<li>Rule origin - Where did the rule originate?</li>
<li>Specificity - How specific is the rule?</li>
<li>Importance - Was the rule declared as <code>!important</code>?</li>
<li>Order - What order were the rules loaded?</li>
</ul>
<div class="source">
Further Reading: <a href="http://reference.sitepoint.com/css/cascade">The Cascade</a>
</div>
</article>
<!-- Resolution Steps -->
<article>
<h3>Resolution Steps</h3>
<p>
Resolving CSS properties is done in four steps
</p>
<ol>
<li>For a given property, find all declarations that apply to a specific element.</li>
<li>Sort the declarations according to their levels of importance, and origins.</li>
<li>Sort declarations with the same level of importance and origin by selector specificity.</li>
<li>Finally, if declarations have the same level of importance, origin, and specificity, sort them by the order in which they’re specified; the last declaration wins.</li>
</ol>
<div class="source">
Source: <a href="http://reference.sitepoint.com/css/cascade">The Cascade</a>
</div>
</article>
<!-- Rule Origin -->
<article>
<h3>Rule Origin</h3>
<p>
The origin of a CSS rule refers the stylesheet where it appears.
</p>
<p>
Rules are imported from three sources:
</p>
<table>
<tr>
<td>
User Agent
</td>
<td>
The default stylesheet for the device rendering the output. This is usually a web
browser but may be a phone, TV, or
<a href="http://media.photobucket.com/image/webos%20toaster/g_manq/webOSToaster.jpg">household appliance</a>.
</td>
</tr>
<tr>
<td>
User Stylesheet
</td>
<td>
Most desktop browsers allow users to provide their own
<a href="https://twitter.com/paul_irish/status/217303604254613504">custom defaults</a>
in the user stylesheet.
</td>
</tr>
<tr>
<td>
Author Stylesheet
</td>
<td>
Any rule imported via a <code>link</code> or <code>style</code> element or in an
element's <code>style</code> attribute.
</td>
</tr>
</table>
</article>
<!-- How Origin is Applied -->
<article>
<h3>How Origin is Applied</h3>
<p>
CSS rule declarations are sorted by origin in the following order from lowest to highest
</p>
<ol>
<li>User agent declarations</li>
<li>Normal declarations in user style sheets</li>
<li>Normal declarations in author style sheets</li>
<li>Important declarations in author style sheets</li>
<li>Important declarations in user style sheets</li>
</ol>
<div class="source">
Further Reading: <a href="http://reference.sitepoint.com/css/cascade">The Cascade</a>
</div>
</article>
<!-- Specificity -->
<article>
<h3>Specificity</h3>
<p>
More specific rules are applied over less specific ones. But how is specificity calculated?
</p>
<p>
Rules are split into 4 categories, a, b, c, d.
</p>
<ul>
<li><strong>a</strong> = 1 if the declaration is inline rather than on a selector, else <strong>a</strong> = 0</li>
<li><strong>b</strong> = the count of the number of ID attributes</li>
<li><strong>c</strong> = the count of other attributes (like class names) and pseudo-classes</li>
<li><strong>d</strong> = the count of element names and pseudo-elements</li>
</ul>
<p>
Concatenating the four counts (in a hex base) gives the specificity
</p>
<div class="source">
Source: <a href="http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/#Specificity">Specificity</a>
</div>
</article>
<!-- Important -->
<article>
<h3>Use of !important</h3>
<p>
The <code>!important</code> directive can override other rules with less specificity.
</p>
<p>
This is akin to the <a href="http://en.wikipedia.org/wiki/Nuclear_option">nuclear option</a>.
</p>
<p>
Treat <code>!important</code> as a code smell.
</p>
</article>
<article>
<h3>Order</h3>
<p>
Understanding order is simple: Last always wins.
</p>
<pre>
<div style="background-color: red;
background-color: lightblue;">
Last always wins.
</div></pre>
<div style="background-color: green; background-color: lightblue; padding: 10px;">
Last always wins.
</div>
</article>
<!-- Segue to Units of Measurement -->
<article class="segue">
<h2>Units of Measurement</h2>
</article>
<!-- Introducing Font-Relative Lengths -->
<article>
<h3>Font-Relative Lengths</h3>
<q style="font-size: 1em; line-height: 45px; margin-left: 75px; margin-right: 75px; margin-top: 40px; text-align: justify;">
Aside from <code>rem</code> (which refers to the font-size of the root element), the font-relative
lengths refer to the computed font metrics of the element on which they are used. The
exception is when they occur in the value of the <code>font-size</code> property itself, in which
case they refer to the font metrics of the parent element (or the font metrics
corresponding to the initial values of the <code>font</code> property, if the element has no parent).
</q>
<div class="source">
Source: <a href="http://www.w3.org/TR/css3-values/#font-relative-lengths">Font-Relative Lengths</a>
</div>
</article>
<!-- Font-Relative Length Details -->
<article class="smaller">
<h3>Font Relative Lengths</h3>
<table>
<tr>
<td>
<code>1.0em</code>
</td>
<td>
Equal to the computed value of the <code>font-size</code>
</td>
</tr>
<tr>
<td>
<code>1.0ex</code>
</td>
<td>
Equal to the height of the lowercase "x"
</td>
</tr>
<tr>
<td>
<code>1.0ch</code>
</td>
<td>
Equal to the height of 0
</td>
</tr>
<tr>
<td>
<code>1.0rem</code>
</td>
<td>
Equal to the computed value of the <code>font-size</code> of the root element
</td>
</tr>
</table>
<pre>h1 { line-height: 1.2em; }</pre>
<p>
The line height of <code>h1</code> elements will be 20% greater than the font size of the <code>h1</code> element
</p>
<pre>h1 { font-size: 1.2em; }</pre>
<p>
The font-size of <code>h1</code> elements will be 20% greater than the inherited font size
</p>
<div class="source">
Source: <a href="http://www.w3.org/TR/css3-values/#font-relative-lengths">Font Relative Lengths</a>
</div>
</article>
<!-- Absolute Lengths -->
<article class="smaller">
<h3>Absolute Lengths</h3>
<q style="font-size: 1em; line-height: 45px; margin-left: 75px; margin-right: 75px; margin-top: 40px; text-align: justify;">
Absolute length units are fixed in relation to each other and anchored to some physical measurement.
</q>
<p>
Some common units of measurement:
</p>
<table>
<tr>
<td><code>cm</code></td>
<td>centimeters</td>
</tr>
<tr>
<td><code>in</code></td>
<td>inches - defined as 2.54cm</td>
</tr>
<tr>
<td><code>px</code></td>
<td>pixel - defined as 1/96th of an inch or the size of the device's reference pixel</td>
</tr>
<tr>
<td><code>pt</code></td>
<td>points - defined as 1/72nd of an inch</td>
</tr>
</table>
<p>
In practice, the best unit of measurement depends on the media.
</p>
<p>
Pixels make sense on screen. Centimeters and inches make sense in printed media.
</p>
<div class="source">
Source: <a href="http://www.w3.org/TR/css3-values/#absolute-lengths">Absolute Lengths</a>
</div>
</article>
<!-- Percentages -->
<article>
<h3>Percentages</h3>
<p>
Percentage values are always relative to some other value. Properties that allow
percentages implicitly define the value to which the percentage refers.
</p>
<pre>
<div style="height: 100px;">
<div style="height: 50%; width: 50%;">
50% as big as the parent
</div>
</div></pre>
<div class="box box1" style="height: 100px;">
<div class="box box2" style="height: 50%; width: 50%;">50% as big as the parent</div>
</div>
<div class="source">
Source: <a href="http://www.w3.org/TR/css3-values/#percentages">Percentages</a>
</div>
</article>
<!-- Viewport Relative Lengths -->
<article>
<h3>Viewport-Relative Units</h3>
<p>
CSS3 introduces viewport-relative units. These are supported in Chrome and IE.
</p>
<p>
Percentages are relative to a value on an ancestor element. Viewport-relative units
are always in relation to the viewport size.
</p>
<table>
<tr>
<td>
vh
</td>
<td>
1% of the viewport height
</td>
</tr>
<tr>
<td>
vw
</td>
<td>
1% of the viewport width
</td>
</tr>
<tr>
<td>
vm
</td>
<td>
The smaller of vh and vw
</td>
</tr>
</table>
<div class="box box1 exampleSpacing" style="width: 40vw; font-size: 20px;">
Viewport-relative unit supported this box is shorter than the slide width.
</div>
<div class="source">
Further Reading: <a href="http://css-tricks.com/viewport-sized-typography/">Viewport-Sized Typography</a>
</div>