1Three ways to add CSS to the body of html:
2 1)External CSS
3 2)Internal CSS
4 3)Inline CSS
5
61) Externally:
7 Type your css code in a file. Remember you file name.
8 Then,
9<head>
10 <link rel="stylesheet" type="text/css" href="FileName.css" >
11</head>
12
132) Internally:
14 Type your cSS in the html file itself. (It is not preffered until
15 little CSS code is to be added). This can be done by style tag.
16 Example:
17 <head>
18 <style>
19 h1 {
20 text-color:red;
21 text-size: 0.8em;
22 }
23 </style>
24 </head>
25
263) Inline:
27 This method is not used by developers as it is very lengthy and
28 maintaining code becomes difficult.
29 Example:
30 <h1 style="color:blue;text-align:center;">Header file</h1>
1/******************* BASIC BLOCK POSITIONING **********************/
2
3/******************** Static Position *************************/
4/*All elements are static in their position by default. Which means
5that, all elements are organized just like they would if your code
6didn't have any CSS and were just pure HTML */
7
8tag_name {
9 position: static;
10}
11
12/******************** Relative Position *************************/
13/*It allow us to position this element relative to how it would have
14been positioned had it been static. You can use the coordinate
15properties to guide this element (by giving some margins to the block),
16relative to what was the standard layout. This new position will not
17influence the distribution of other elements (the others will keep
18the standard layout, as if your element leaves a "shadow" of where it
19was supposed to be). Therefore, some overlaps and lack of coordination
20can occur when you move your element*/
21
22tag_name {
23 position: relative;
24 left: 30px;
25 right: 10px;
26 bottom: 2px;
27 top: 4px;
28
29 z-index: 1; /* It decides which element will show on top of the
30 other. The first to show, is the one with the
31 greatest index */
32}
33
34/******************** Absolute Position *************************/
35/* With this property, we are able to position the element relative
36to the <body> or relative to it's parent, IF the parent is itself isn't
37"static". Using the coordination properties, we do not increase or
38decrease the margins in relation to the standard position, but rather,
39we are increasing or decreasing the distance in relation to the "walls"
40of the block that contains this element, for example, a parent <div>
41that contains a <h1> element. The name "absolut", comes from the cases
42where the parent is the <body> element. When you use this property,
43you are taking the element away from the natural flow of your document,
44so, the other elements position will not take into account your absolute
45element*/
46
47tag_name {
48 position: absolute;
49 left: 30px;
50 right: 10px;
51 bottom: 2px;
52 top: 4px;
53
54 z-index: 1; /* It decides which element will show on top of the
55 other. The first to show, is the one with the
56 greatest index */
57}
58
59/* For exemple: */
60
61div{
62 position: relative;
63}
64
65h1 {
66 position: absolute; /* In relation to the div element*/
67 left: 30px;
68 top: 4px;
69}
70
71/******************** Fixed Position *************************/
72/*As soon as the element is fixed in a certain position, relative
73to it's parent, then, whenever we scroll down the webpage, the element
74maintains its fixed position on the screen. This property will also
75make the other html elements, ignore the position of this element
76during their layout (it takes it away from the natural flow of the
77document). */
78
79tag_name {
80 position: fixed;
81 left: 30px;
82 right: 10px;
83 bottom: 2px;
84 top: 4px;
85
86 z-index: 2; /* It decides which element will show on top of the
87 other. The first to show, is the one with the
88 greatest index */
89}
90
91/******************** Sticky Position *************************/
92/* This property will stick the element to the screen when you
93reach its scroll position */
94
95tag_name {
96 position: -webkit-sticky; /* For Safari */
97 position: sticky;
98 left: 20px;
99 right: 60px;
100 bottom: 5px;
101 top: 13px;
102
103}
104
105/******************* NOTES ABOUT THE Z-INDEX **********************/
106/* By default, the z-index of an element is zero, so if you change the
107z-index to something above or below that value, you are putting that
108element above or below the ones you didn't change.
109Another important thing to be aware of is that the z-index only worked
110for elements that have a position different from the standard. This
111means that, for elements with Static position, this won't work.
112So, you can only make two elements interact in the z plane if they both
113have a define position as: Relative, Absolute, Fixed, ... */
114
115tag_name_1 {
116 position: absolute;
117 z-index: -1;
118
119}
120
121tag_name_2 {
122 position: relative; /* tag_name_1 will be below the tag_name_2 */
123}
124
1
2/******************* BASIC BLOCK DISPLAY **********************/
3
4/**************** Block display Elements *********************/
5/*Elements that block any other elements from being in the
6same line. You can change the width from being the maximum
7width of the page, but you can´t put elements side by side */
8tag_name {
9 display: block;
10}
11
12/*Exemple of default block display elements:*/
13<h1> ... </h1>
14<p> ... </p>
15
16
17/**************** Inline display Elements *********************/
18/*They are the type of blocks that only take up the minimum space
19required (both in width and height). You can place these types of
20blocks side by side (on the same line) but you cannot change their
21dimensions */
22
23tag_name {
24 display: inline;
25}
26
27/*Exemple of default inline display elements:*/
28<spans> ... </spans>
29<img> ... </img>
30<a> ... </a>
31
32
33/************* Inline-block display Elements *****************/
34/*They take the best of the two other types above. You can put
35elements side by side (on the same line) and you can change this
36block width and height */
37
38tag_name {
39 display: inline-block;
40}
41
42
43/***************** None display Elements ********************/
44/*This block will never appear on your webpage and will never
45interact with the other elements (it doesn't take up space) */
46
47tag_name {
48 display: none;
49}
50
1/*Compared to display: inline, the major difference is that
2display: inline-block allows to set a width and height on the element.
3
4Also, with display: inline-block, the top and bottom margins/paddings are
5respected, but with display: inline they are not.
6
7Compared to display: block, the major difference is that
8display: inline-block does not add a line-break after the element,
9so the element can sit next to other elements.
10
11The following example shows the different behavior of
12display: inline, display: inline-block and display: block: */
13
14
15span.a {
16 display: inline; /* the default for span */
17 width: 100px;
18 height: 100px;
19 padding: 5px;
20 border: 1px solid blue;
21 background-color: yellow;
22}
23
24span.b {
25 display: inline-block;
26 width: 100px;
27 height: 100px;
28 padding: 5px;
29 border: 1px solid blue;
30 background-color: yellow;
31}
32
33span.c {
34 display: block;
35 width: 100px;
36 height: 100px;
37 padding: 5px;
38 border: 1px solid blue;
39 background-color: yellow;
40}