-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSS-interm-notes.txt
661 lines (277 loc) · 9.07 KB
/
CSS-interm-notes.txt
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
GROUPING
Instead of doing something like:
h2 {
color: red;
}
.thisOtherClass {
color: red;
}
.yetAnotherClass {
color: red;
}
/* You can do something like: */
h2, .thisOtherClass, .yetAnotherClass {
color: red;
}
NESTING
You can apply properties to selecors within other selectors.
#top {
background-color: #ccc;
padding: 1em
}
#top h1 {
color: #ff0;
}
#top p {
color: red;
font-weight: bold;
/* This would work well on HTML that appears as: */
div id="top">
<h1>Chocolate curry</h1>
<p>This is my recipe for making curry purely with chocolate</p>
<p>Mmm mm mmmmm</p>
</div>
PSEUDO SELECTORS
Pseudo classes are bolted on to selectors to specify a state or relation to the selector.
They take the form of selector:pseudo_class { property: value; }
Simply with a colon in between the selector and the pseudo class.
->LINKS
link : Targeting Unvisited Links
visited : Targeting Visited Links
The following will apply colors to all links in a page depending on
whether the user has visited that page before or not:
a:link {
color: blue;
}
a:visited {
color: purple;
}
->DYNAMIC PSEUDO CLASSES
Also commonly used for links. Can be used to apply
styles when something happens to something.
:active When something is activated by user input, such as a user clicking on something.
:hover When something is activated by being passed over. Link a mouse moving over.
:focus When something is the focus, and ready for keyboard input.
->This can be used for text boxes and forms, but is also useful for links for non-mouse users.
a:active {
color: red;
}
a:hover {
text-decoration: none;
color: blue;
background-color: yellow;
}
input:focus, textarea:focus {
background: #eee;
}
-> FIRST CHILDREN
:first-child This will target something only if it is the first descendent of an element.
So, in the following HTML:
<body>
<p>I’m the body’s first paragraph child. I rule. Obey me.</p>
<p>I resent you.</p>
</body>
…if you only want to style the first paragraph, you could use the following CSS:
p:first-child {
font-weight: bold;
font-size: 40px;
}
->There are many more pseudo-classes. Such as last-child, last target, first of type, and more
=>Look these up
SHORTHAND PROPERTIES
Some CSS properties allow a string of values, replacing the need for a number of properties.
These are represented by values separated by spaces.
the margin property allows you to combine its 4 values: top, right, bottom, left as:
margin: top right bottom left
(e.g.): margin: 0px 10px 0px 10px;
padding can be used in the same way:
padding: 0px 10px 0px 10px;
by stating just two values, such as
padding: 1em 10em;
the first value will be top and bottom
the second valuen will be right and left
->BORDER SHORTHAND
border-width: 20px;
border-color: red;
border-style: solid;
Can be simplified as
border: 20px red solid;
This can also be applied to border-top, border-right, border-bottom, border-left.
->FONT SHORTHAND
font:font-style, font-type, font-size/line-height font-family;
These can all be combined into one line:
p {
font: italic bold 12px/2 courier;
}
Combine all these shorthands together and you get.
p {
font: 14px/1.5 "Times New Roman", times, serif;
padding: 30px 10px;
border: 1px black solid;
border-width: 1px 5px 5px 1px;
border-color: red green blue yellow;
margin: 10px 50px;
}
BACKGROUND IMAGES
body {
background: white url(http://www.htmldog.com/images/bg.gif) no-repeat top right;
}
This is an amalgamation of
background-color:
background-image: url()
background-repeat:
background-position: top; center; bottom; left; right; #px; %; top right; bottom left; ...etc
CALCULATING SPECIFICITY
The actual specificity of a group of nested selectors takes some calculating.
You can give every ID selector (#whatever) a value of 100
Every class selector (.whatever) a value of 10
Every HTML selector (whatever) a value of 1.
When you add them all up, you have the value of specificity for that selector.
p has a specificity of 1 (1 HTML selector)
div p has a specificity of 2 (2 HTML selectors, 1+1)
.tree has a specificity of 10 (1 class selector)
div p.tree has a specificity of 12 (2 HTML selectors + a class selector, 1+1+10)
#baobab has a specificity of 100 (1 id selector)
body #content .alternative p has a specificity of 112
(HTML selector + id selector + class selector + HTML selector, 1+100+10+1)
DISPLAY TYPES
display: inline;
display: block;
display: none;
->display: inline;
display: inline; will display all items inline with each other on a page
<ol>
<li></li>
<li></li>
<li></li>
</ol>
li {
display: inline;
}
This will make all list items to appear inline with each other.
li li li li
->display: block;
display: block; Will display all items in a block, with space between.
A margin, padding, and height value can be given to this
#navigation a {
display: block;
padding: 20px 10px;
}
This would make all links in id="nav" boxes with 20px top and bottom, 10px right and left.
->display: inline-block
Keeps the blocks made in line, allowing margins between them.
->display: none;
Will make something stop displaying.
Can be used for clickable links and things that will make something
dissappear from the page. It is no longer loaded into the page.
visibility: hidden
this is similar to display: none, except that the item will still remain on the page.
CSS TABLES
table is the initial display and you can mimic the tr and td elements with the
table-row and table-cell property values respectively.
The display property goes further by offering
table-column,
table-row-group,
table-column-group,
table-header-group,
table-footer-group
table-caption as values, which are all quite self-descriptive. The immediately obvious benefit of these values is that you can construct a table by columns, rather than the row-biased method used in HTML.
Finally, the value inline-table basically sets the table without line breaks before and after it.
PSEUDO ELEMENTS
selector:element {
}
-> First Lines
p {
font-size: 12px;
}
p:first-letter {
font-size: 24px;
float: left;
}
p:first-line {
font-weight: bold;
}
This would make the first letter of <p> font-size: 24px; and float:left;
This would make the first line of text in <p> font-weight:bold;
BEFORE AND AFTER
CONTENT
blockquote:before {
content: open-quote;
}
blockquote:after {
content: close-quote;
}
li:before {
content: "POW! ";
}
p:before {
content: url(images/jam.jpg);
}
These make it so that there is information contained to the left or right of the element you're selecting.
the value in content can be
content: open-quote;
content: close-quote;
content: "any thing you want (this is a string)"; -> in quotes
content: url(image-location.png);
This effectively makes another box that you can manipulate
li:before {
content: "POW! ";
background: red;
color: #fc0;
}
PAGE LAYOUT
"You take a chunk of your page and shove it wherever you want it to go"
->positioning
position: static
this is the default value and positions things as they would from HTML alone.
position: relative
top: 20px;
right:300px
this moves the position relative to where it places by default
position: absolute;
bottom: 200px;
left: 45px;
this allows the box to be freely plaved anywhere on the page
For example, a two column layout can be made with absolute positioning:
<div id="navigation">
<ul>
<li><a href="this.html">This</a></li>
<li><a href="that.html">That</a></li>
<li><a href="theOther.html">The Other</a></li>
</ul>
</div>
<div id="content">
<h1>Ra ra banjo banjo</h1>
<p>Welcome to the Ra ra banjo banjo page. Ra ra banjo banjo. Ra ra banjo banjo. Ra ra banjo banjo.</p>
<p>(Ra ra banjo banjo)</p>
</div>
then in CSS
#navigation {
position: absolute;
top: 0;
left: 0;
width: 200px;
}
#content {
margin-left: 200px;
}
position: fixed;
top: 200px;
left: 150px;
FLOAT
Floating a box will shift it to the right or left of a line
float: right;
float: left;
If you don't want the next box to wrap around the floating objects
You can add the "clear" property
clear: right;
clear: left;
clear: both;
For Example:
<div id="footer">
<p>Footer! Hoorah!</p>
</div>
#footer {
clear: both;
}
This will make a footer that will be below any table no matter its length.