-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCSS.css
1631 lines (1032 loc) · 42.9 KB
/
CSS.css
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
/* -------------------------------------------------- */
CSS
/* -------------------------------------------------- */
Control your specificity
Be modular and create reusable style
Ease maintenance
Work better as a team
Write less to achieve more
/* -------------------------------------------------- */
DOM
/* -------------------------------------------------- */
DOM
A DOM has a tree-like structure. Each element, attribute and piece of text in the markup language becomes a DOM node in the tree structure. The nodes are defined by their relationship to other DOM nodes. Some elements are parents of child nodes, and child nodes have siblings.
Load HTML --> Parse HTML
Load CSS --> Parse CSS
Create DOM Tree
Display
/* -------------------------------------------------- */
Apply CSS to HTML
/* -------------------------------------------------- */
External /* best */
<link rel="stylesheet" href="style.css">
Internal
<style>
...
</style>
Inline Style
<h1 style="color: blue;background-color: yellow;border: 1px solid black;">Hello World!</h1>
<p style="color:red;">This is my first CSS example</p>
The only time you might have to resort to using inline styles is when your working environment is really restrictive (perhaps your CMS only allows you to edit the HTML body.)
/* -------------------------------------------------- */
Syntax
/* -------------------------------------------------- */
CSS Declaration
body {
property : value ;
property : value /* ; not needed */
}
Selector Ruleset
div p, #id:first-line
{
property : value ;
property : value /* ; not needed */
}
CSS Statements
At-rules @
/* @charset */
/* @media */
Applied only if the device which runs the browser matches the expressed condition;
@media (min-width: 801px)
{
body
{
margin: 0 auto;
width: 800px;
}
}
/* @supports */
Applied only if the browser actually supports the tested feature;
/* @document */
Applied only if the current page matches some conditions.
/* @font-face */
/* @import */
@import 'custom.css';
Imports another CSS file into the current CSS.
/* -------------------------------------------------- */
Comment Styles
/* -------------------------------------------------- */
/* Handle basic element styling */
/* --------------------------------------------------------------- */
body {font: 1em/150% Helvetica, Arial, sans-serif; padding: 1em; margin: 0 auto; max-width: 33em;}
@media (min-width: 70em) {
/* Let's special case the global font size. On large screen or window,
we increase the font size for better readability */
body {font-size: 130%;}
}
h1 {font-size: 1.5em;}
/* Handle specific elements nested in the DOM */
/* --------------------------------------------------------------- */
div p, #id:first-line {background-color: red; background-style: none}
div p {margin : 0; padding : 1em;}
div p + p {padding-top : 0; }
/* -------------------------------------------------- */
Selectors
/* -------------------------------------------------- */
Simple selectors
Match one or more elements based on element type, class, or id.
/* All p elements are red */
p {
color: red;
}
/* The element with the class "first" is bolded */
.first {
font-weight: bold;
}
Handling multiple classes
/* CSS */
.base-box {
background-image: linear-gradient(to bottom, rgba(0,0,0,0.1), rgba(0,0,0,0.3));
padding: 3px 3px 3px 7px;
}
.important {
font-weight: bold;
}
.editor-note {
background-color: #9999ff;
border-left: 6px solid #333399;
}
.warning {
background-color: #ff9999;
border-left: 6px solid #993333;
}
/* HTML */
<p class="base-box warning important">My first paragraph.</p>
ID selectors
#polite {
font-family: cursive;
}
Universal Selector
Careful when using the universal selector. As it applies to all elements, using it in large web pages can have a perceptible impact on performance: web pages can be displayed slower than expected. There are not many instances where you'd want to use this selector.
* {
padding: 5px;
border: 1px solid black;
background: rgba(255,0,0,0.25)
}
/* -------------------------------------------------- */
Attribute selectors
Match one or more elements based on their attributes/attribute values.
Attribute selectors are a special kind of selector that will match elements based on their attributes and attribute values. Their generic syntax consists of square brackets ([]) containing an attribute name followed by an optional condition to match against the value of the attribute. Attribute selectors can be divided into two categories depending on the way they match attribute values: Presence and value attribute selectors and Substring value attribute selectors.
<ul>
<li data-quantity="2kg" data-meat>Chicken</li>
<li data-quantity="1kg" data-vegetable>Tomatoes</li>
<li data-quantity="optional 10ml" data-vegetable="liquid">Olive oil</li>
<li data-quantity="700g" data-vegetable="not spicy like chili">Red pepper</li>
</ul>
[data-vegetable] {
color: green
}
[data-vegetable="liquid"] {
color: green
}
[data-vegetable~="spicy"] {
color: red;
}
Substring Value Selectors
[attr|=val]
This selector will select all elements with the attribute attr for which the value is exactly val or starts with val- (careful, the dash here isn't a mistake, this is to handle language codes.)
[attr^=val]
This selector will select all elements with the attribute attr for which the value starts with val.
[attr$=val]
This selector will select all elements with the attribute attr for which the value ends with val.
[attr*=val]
This selector will select all elements with the attribute attr for which the value contains the string val (unlike [attr~=val], this selector doesn't treat spaces as value separators but as part of the attribute value.)
[lang|=fr] {
font-weight: bold;
}
/* All elements with the attribute "data-vegetable" containing
the value "not spicy" are turned back to green */
[data-vegetable*="not spicy"] {
color: green;
}
/* All elements with the attribute "data-quantity", for which
the value ends with "kg" */
[data-quantity$="kg"] {
font-weight: bold;
}
/* All elements with the attribute "data-quantity", for which the
value starts with "optional" */
[data-quantity^="optional"] {
opacity: 0.5;
}
/* -------------------------------------------------- */
Pseudo-classes
Match one or more elements that exist in a certain state, such as an element that is being hovered over by the mouse pointer, or a checkbox that is currently disabled or checked, or an element that is the first child of its parent in the DOM tree.
A CSS pseudo-class is a keyword preceded by a colon (:) that is added on to the end of selectors to specify that you want to style the selected elements only when they are in certain state.
:active
:any
:checked
:default
:dir()
:disabled
:empty
:enabled
:first
:first-child
:first-of-type
:fullscreen
:focus
:hover
:indeterminate
:in-range
:invalid
:lang()
:last-child
:last-of-type
:left
:link
:not()
:nth-child()
:nth-last-child()
:nth-last-of-type()
:nth-of-type()
:only-child
:only-of-type
:optional
:out-of-range
:read-only
:read-write
:required
:right
:root
:scope
:target
:valid
:visited
a:visited {
color: blue;
}
a:hover,
a:active,
a:focus {
color: darkred;
text-decoration: none;
}
/* -------------------------------------------------- */
Pseudo-elements
Match one or more parts of content that are in a certain position in relation to an element, for example the first word of each paragraph, or generated content appearing just before an element.
Pseudo-elements are very much like pseudo-classes, but they have differences. They are keywords — this time preceded by two colons (::) — that can be added to the end of selectors to select a certain part of an element.
::after
::before
::first-letter
::first-line
::selection
::backdrop
<ul>
<li><a href="https://developer.mozilla.org">CSS</a></li>
<li><a href="https://developer.mozilla.org">HTML</a></li>
</ul>
/* All elements with an attribute "href", which values
start with "http", will be added an arrow after its
content (to indicate it's an external link) */
[href^=http]::after {
content: '>';
}
/* -------------------------------------------------- */
Combinators
These are not exactly selectors themselves, but ways of combining two or more selectors in useful ways for very specific selections. So for example, you could select only paragraphs that are direct descendants of divs, or paragraphs that come directly after headings.
AB
Any element matching both A and B at the same time.
A B
Any element matching B that is a descendant of an element matching A (that is: a child, or a child of a child, etc.)
A > B
Any element matching B that is a direct child of an element matching A.
A + B
Any element matching B that is the next sibling of an element matching A (that is: the next child of the same parent.)
A ~ B
Any element matching B that is among the next sibling of an element matching A (that is: one of the next children of the same parent.)
/* All <td>s within a <table> and all <th>s within a <table>
Comma is not a combinator, it just allows you to target
several selectors with the same CSS ruleset */
table td, table th {
border : 1px solid black;
padding: 0.5em 0.5em 0.4em;
}
/* All <th>s within <thead>s that are within <table>s */
table thead th {
color: white;
background: black;
}
/* All <td>s preceded by another <td>,
within a <tbody>, within a <table> */
table tbody td + td {
text-align: center;
}
/* All <td>s that are a last child,
within a <tbody>, within a <table> */
table tbody td:last-child {
text-align: right
}
/* All <th>s, within a <tfoot>s, within a <table> */
table tfoot th {
text-align: right;
border-top-width: 5px;
border-left: none;
border-bottom: none;
}
/* All <td>s preceded by a <th>, within a <table> */
table th + td {
text-align: right;
border-top-width: 5px;
color: white;
background: black;
}
/* All pseudo-elements "before" <td>s that are a last child,
appearing within elements with a class of "with-currency" that
also have an attribute "lang" with the value "en-US" */
.with-currency[lang="en-US"] td:last-child::before {
content: '$';
}
/* All pseudo-elements "after" <td>s that are a last child,
appearing within elements with the class "with-currency" that
also have an attribute "lang" with the value "fr" */
.with-currency[lang="fr"] td:last-child::after {
content: ' €';
}
/* -------------------------------------------------- */
Multiple selectors
You can write multiple selectors separated by commas, to apply the same rule to multiple sets of selected elements at once.
h1, h2, h3, h4, h5, h6 {
font-family: helvetica, 'sans serif';
}
/* -------------------------------------------------- */
SMACSS : Scalable and Modular Architecture CSS
/* -------------------------------------------------- */
Base
This include selector rules. No classes or id here. This is to reset browser rules and set a base style for elements which are going to be consistent and reused. You are defining here the default style for your elements. This can include html, body, h1, h2, h3, h4, h5, h6, img, a…
Layout
This is where the style used to lay out your pages will sit. It should be separated to your module style for flexibility. You want to be able to use your layout style to build your pages in the most flexible way possible. A module or components should be added to any place in your site independent from the layout.
Modules
A module is a part or a component of your page. Your menu, dialog box, download list or any widget you have on your page. It depends of your design.
A module is independent from your layout so it can live anywhere in you app. You should be able to copy/paste the html and move somewhere else, and it will look and behave the same.
A module should be encapsulated in one file and easily accessible. It will be easy to find and you’ll be in control of what you want to update as it won’t be depending on any other style.
States
A state will be a style which modifies or overrides other rules. A great example is accordion when collapsing or expanding elements. Using a `is-collapsed` class will make sure your element is collapsed. This is a good place to use !important (and probably the only one) as you want this state to be applied no matter what. Also, it can relate to modified state with javascript.
Good practise is to prefix or add a namespace to those states classes like is- or has-: is-hidden, is-displayed, is-collapsed, has-children, etc
Theme
Idea is to have a file called theme.css where you can define all the theme rules.
// box.scss
.box {
border: 1px solid;
}
// theme.scss
.box {
border-color: red;
}
/* -------------------------------------------------- */
CSS Values and Units
/* -------------------------------------------------- */
Numeric values
Length values for specifying e.g. element width, border thickness, or font size, and unitless integers for specifying e.g. relative line width or number of times to run an animation.
Percentages
Can also be used to specify size or length — relative to a parent container's width or height for example, or the default font-size.
Colors
For specifying background colors, text colors, etc.
Coordinate positions
e.g. for specifying the position of a positioned element relative to the top left of the screen.
Functions
For specifying e.g. background images or background image gradients.
/* -------------------------------------------------- */
Length and Size
margin: 5px;
padding: 10px;
border: 2px
width: 150px;
font-size: 18px;
px (pixel)
absolute units, same size regardless of any other related settings
mm, cm, in
Millimeters, centimeters, or inches
pt, pc
Points (1/72 of an inch) or picas (12 points.)
em
1em is the same as the font-size of the current element (more specifically, the width of a capital letter M.) The default base font-size given to web pages by web browsers before CSS styling is applied is 16 pixels, which means the computed value of 1em is 16 pixels for an element by default. But beware — font sizes are inherited by elements from their parents, so if different font sizes have been set on parent elements, the pixel equivalent of an em can start to become complicated.
ex, ch
Respectively these are the height of a lower case x, and the width of the number 0. These are not as commonly used or well-supported as ems.
rem
The rem (root em) works in exactly the same way as the em, except that it will always equal the size of the default base font-size; inherited font sizes will have no effect, so this sounds like a much better option than ems, although rems don't work in older versions of Internet Explorer.
vw, vh
Respectively these are 1/100th of the width of the viewport, and 1/100th of the height of the viewport. Again, these are not as widely supported as rems.
Unitless Values
For example, if you want to completely remove the margin or padding from an element, you can just use unitless 0 — 0 is 0, no matter what units were set before!
margin: 0;
line-height: 1.5;
CSS Animations
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
p:hover {
animation-name: rotate;
animation-duration: 0.6s;
animation-timing-function: linear;
animation-iteration-count: 5;
}
Percentages
font-size: 200%;
width: 75%;
Colour
Hexadecimal values
background-color: #ff0000; /* red */
RGB
background-color: rgb(255,0,0);
HSL
Slightly less well supported than RGB is the HSL model (not on old versions of IE), which was implemented after much interest from designers — instead of red, green and blue values, the hsl() function accepts hue, saturation, and lightness values, which are used to distinguish between the 16.7 million colors, but in a different way
hue
the base shade of the color. This takes a value between 0 and 360, presenting the angles round a color wheel.
saturation
how saturated is the color? This takes a value from 0-100%, where 0 is no color (it will appear as a shade of grey), and 100% is full color saturation
lightness
how light, or bright is the color? This takes a value from 0-100%, where 0 is no light (it will appear completely black) and 100% is full light (it will appear completely white)
background-color: hsl(0,100%,50%);
background-color: hsl(240,100%,50%);
RGBA (transparency)
background-color: rgba(255,0,0,0.5);
HSLA (transparency)
background-color: hsla(240,100%,50%,0.5);
Obacity
opacity: 0.5;
/* -------------------------------------------------- */
Cascade and inheritance
/* -------------------------------------------------- */
Cascading Style Sheets
Which style will override which?
Importance
lways win over all others
border: none !important;
Specificity
Specificity is basically a measure of how specific a selector is, in terms of how many elements it could match. As shown in the example seen above, element selectors have low specificity. Class selectors have a higher specificity, so will win against element selectors. ID selectors have an even higher specificity, so will win against class selectors. The only way to win against an ID selector is to use !important.
/* weight: 0101 */
#outer a {
background-color: red;
}
/* weight: 0201 */
#outer #inner a {
background-color: blue;
}
/* weight: 0104 */
#outer div ul li a {
color: yellow;
}
Source order
later rules will win over earlier rules
p {
color: blue;
}
/* This rule will win over the first one */
p {
color: red;
}
/* This rule will win by specificity*/
.footnote {
color: blue;
}
p {
color: red;
}
/* -------------------------------------------------- */
Inheritance
inherit
This value sets the property value applied to a selected element to be the same as that of its parent element.
initial
This value sets the property value applied to a selected element to be the same as the value set for that element in the browser's default style sheet. If no value is set by the browser's default style sheet and the property is naturally inherited, then the property value is set to inherit instead.
unset
This value resets the property to its natural value, which means that if the property is naturally inherited it acts like inherit, otherwise it acts like initial.
body {
color: green;
}
.inherit a {
color: inherit;
}
.initial a {
color: initial
}
.unset a {
color: unset;
}
/* -------------------------------------------------- */
CSS Box Model
/* -------------------------------------------------- */
Every element within a document is structured as a rectangular box inside the document layout, the size and "onion layers" of which can be tweaked using some specific CSS properties.
margin --> border --> padding --> [content]
content
width
height
The width and height properties set the width and height of the content box, which is the area in which the content of the box is displayed — this content includes both text content sat inside the box, and other boxes representing nested child elements.
padding
The padding box represents the inner margin of a CSS box — the layer between the outer edge of the content box and the inner edge of the border. The size of this layer can be set on all four sides at once with the padding shorthand property, or one side at a time with the padding-top, padding-right, padding-bottom and padding-left properties.
border
The border of a CSS box is a distinct layer, sitting between the outer edge of the padding and the inner edge of the margin. By default the border has a size of 0 — making it invisible — but you can set the thickness, style and color of the border to make it appear.
border-top, border-right, border-bottom, border-left
Set the thickness, style and color of one side of the border.
border-width, border-style, border-color
Set only the thickness, style, or color individually, but for all four sides of the border.
You can also set one of the three properties of a single side of the border individually, using border-top-width, border-top-style, border-top-color, etc.
margin
The margin represents the outer area surrounding the CSS box, which pushes up against other CSS boxes in the layout. It behaves rather like padding; the shorthand property is margin and the individual properties are margin-top, margin-right, margin-bottom, and margin-left.
/* -------------------------------------------------- */
Advanced box manipulation
Overflow
When you set the size of a box with absolute values (e.g. a fixed pixel width/height), the content may not fit within the allowed size, in which case the content overflows the box. To control what happens in such cases, we can use the overflow property.
auto
If there is too much content, the overflowing content is hidden and scroll bars are shown to let the user scroll to see all the content.
hidden
If there is too much content, the overflowing content is hidden.
visible
If there is too much content, the overflowing content is shown outside of the box (this is usually the default behavior.)
.autoscroll { overflow: auto; }
.clipped { overflow: hidden; }
.default { overflow: visible; }
/* -------------------------------------------------- */
Debugging
/* -------------------------------------------------- */
Just like HTML, CSS is permissive. In CSS's case, if a declaration is invalid (contains a syntax error, or the browser doesn't support that feature), the browser just ignores it completely and moves on to the next one it finds.
If a selector is invalid, then it doesn't select anything, and the whole rule does nothing — again, the browser just moves on to the next rule.
Web Developer Tool
Inspect DOM --> See CSS rules applied
CSS Validator
W3C CSS Validation Service
/* -------------------------------------------------- */
z-index
/* -------------------------------------------------- */
The z-index property specifies the z-order of a positioned element and its descendants. When elements overlap, z-order determines which one covers the other. An element with a larger z-index generally covers an element with a lower one.
auto
The box does not establish a new local stacking context. The stack level of the generated box in the current stacking context is the same as its parent's box.
z-index: auto;
<integer>
This integer is the stack level of the generated box in the current stacking context. The box also establishes a local stacking context in which its stack level is 0. This means that the z-indexes of descendants are not compared to the z-indexes of elements outside this element.
z-index: 0;
z-index: 3;
z-index: 289;
z-index: -1; /* Negative values to lower the priority */
Global values
z-index: inherit;
z-index: initial;
z-index: unset;
/* -------------------------------------------------- */
Floats
/* -------------------------------------------------- */
/* img on left, words flow around it */
<img src="butterfly.jpg">
<p> ... </p>
img {
float: left;
margin: 0 30px 0 0;
}
/* 2-column layout */
The :nth-of-type(n) selector matches every element that is the nth child, of a particular type, of its parent.
div:nth-of-type(1) {
width: 48%;
float: left;
}
div:nth-of-type(2) {
width: 48%;
float: right;
}
/* 3-column layout */
div:nth-of-type(1) {
width: 36%;
float: left;
}
div:nth-of-type(2) {
width: 30%;
float: left;
margin-left: 4%;
}
div:nth-of-type(3) {
width: 26%;
float: right;
}
/* clear */
stop floating here
footer {
clear: both;
}
none
Is a keyword indicating that the element is not moved down to clear past floating elements.
left
Is a keyword indicating that the element is moved down to clear past left floats.
right
Is a keyword indicating that the element is moved down to clear past right floats.
both
Is a keyword indicating that the element is moved down to clear past both left and right floats.
inline-start
Is a keyword indicating that the element is moved down to clear floats on start side of its containing block, that is the left floats on ltr scripts and the right floats on rtl scripts.
inline-end
Is a keyword indicating that the element is moved down to clear floats on end side of its containing block, that is the right floats on ltr scripts and the left floats on rtl scripts.
/* -------------------------------------------------- */
Issues
The whole width can be tricky to calculate
Solution
box-sizing
Makes the box model change so the width of the box is taken as content + padding + border, not just content — so adding padding and border won't make the box any wider — it'll just make the content narrower to accomodate.
* {
box-sizing: border-box;
}
/* -------------------------------------------------- */
Issues
Add margin-top to footer against above floating columns
Solution
/* columns above */
<div class="clearfix"></div>
/* footer below */
.clearfix {
clear: both;
}
/* -------------------------------------------------- */
ALL: INITIAL;
/* -------------------------------------------------- */
Effectively stops inheritance.
Prevents legacy styles from leaking into fresh work.
A very progressive way of defending against legacy.
p {
all: initial;
}
/* -------------------------------------------------- */
DEFENSE.CSS
/* -------------------------------------------------- */
old.css --> defense.css --> new.css
Fixes for collisions between old.css and new.css.
Contains hacks, crude code, etc.
Remove old.css and defense.css at end of project.
/* -------------------------------------------------- */
BEM - Block Element Modifier
/* -------------------------------------------------- */
Naming concention for modular/object-oriented CSS