forked from srisi/github_pages_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyling.html
More file actions
178 lines (153 loc) · 8.96 KB
/
styling.html
File metadata and controls
178 lines (153 loc) · 8.96 KB
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
<!DOCTYPE html>
<html lang="en">
<!--The head contains metadata about our page and it's the place where we can load css files (for -->
<!--styling) and javascript files.-->
<head>
<meta name="author" content="Stephan Risi">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Load JQuery and Bootstrap. They are javascript library that handle the layouting for us.-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<!-- The nav bar remains the same for every page, so by defining it in only one file, we only
need to edit it in one place when we make changes to it. -->
<script> $(function(){$("#header").load("header.html");});</script>
<!-- Import the css file, which defines how our website looks -->
<link href="css/main.css" rel="stylesheet">
<link href="css/styling_page.css" rel="stylesheet">
<!--Set the title for the page-->
<title>CSS Styling</title>
</head>
<!--We define the elements that we actually want to display in the body element-->
<body>
<!--This element is a placeholder for the header with the navbar, which we load above-->
<div id="header"></div>
<div class="column">
<h1>Styling with CSS</h1>
<p>What if you want to change how your page looks? Say you want to use
different fonts, draw borders around some elements, or even create animations?</p>
<p>This is where Cascading Style Sheets (CSS) come into play. HTML files define <i>what</i>
should be displayed on the page. CSS files specify <i>how</i> it should look.</p>
<p>Take our standard heading:</p>
<h2>Title</h2>
<p>We could make it larger and change the font:</p>
<h2 class="header_large">Title</h2>
<p>Or we can add a text shadow:</p>
<h2 class="header_text_shadow">Title</h2>
<p>All of our styling information can be found in <a href="https://github.com/srisi/
github_pages_tutorial/blob/master/css/main.css">main.css</a> in the css folder. Here's
a small sample from that file:</p>
<p><img src="images/tutorials/styling_selectors1.png"
alt="Screenshot from css/main.css"></p>
<p>Each component in the css file has two parts: the selector (in green) and the
applied styles (in blue).</p>
<p>For example, <code> h2 { padding-top: 30px; }</code> means: Select all h2 (heading2)
elements and add 30 pixels of padding (whitespace) above them.</p>
<p>
<code>p { <br/>
font-size: 1.4rem;<br/>
line-height: 2rem;<br/>
}
</code>
</p>
<p>This means: Select all paragraph elements and increase the font size to 1.4 times its
default value (16pts) and make each line two default values (2 * 16 pts) high.</p>
<p>If we want to change the font for all paragraphs to Arial, we can just add a third
line to this selector:</p>
<p>
<code>p { <br/>
font-size: 1.4rem;<br/>
line-height: 2rem;<br/>
font-family: arial;<br/>
}
</code>
</p>
<p>There is an almost infinite number of modifications that you can make with CSS.
<a href="https://www.w3schools.com/css/">W3 Schools</a> has a good tutorial available.
Very often, though, the most effective way of finding what you're looking for is to
just google for the setting that you need. Want to underline some text? Google "text
underline css" and you'll land on the <a
href="https://www.w3schools.com/cssref/pr_text_text-decoration.asp"> text-decoration</a>
property.</p>
<h2>Class Selectors</h2>
<p>
Usually, you don't want to globally change the style of all paragraph or heading
elements but rather only those of a select few. You can accomplish this with
class selectors. What that means is that you assign classes to the elements that you
want to change.
</p>
<p>Let's say that we have a blog post with two paragraphs:</p>
<p>
<code>
<p>1: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.</p> <br/>
<p>2: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.</p>
</code>
</p>
<p>If we want to change the font for the first paragraph, we can give it the class
"font_arial":</p>
<p>
<code>
<p class="font_arial" >1: Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.</p> <br/>
<p>2: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.</p>
</code>
</p>
<p>Adding the class does not do anything on its own. But we can now modify the font
for just this class in main.css by adding:</p>
<p>
<code>.font_arial { <br/>
font-family: arial, sans-serif;<br/>
}
</code>
</p>
<p>Note: to select all members of a class, you need to put a period before the class
name, e.g. <code>.font_arial</code>.</p>
<p><br/>Voila, our two paragraphs now use different fonts:</p>
<p class="demo_font_arial">1: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.</p>
<p>2: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.</p>
<h2>Interactive Experiments</h2>
<p>If you just want to experiment with ideas, interactive developer tools are your
friend.</p>
<p>To access the developer tools in Chrome, right click on an element that you want to
change and select "Inspect."</p>
<p><img src="images/tutorials/styling_inspect.png"
alt="Screenshot of selecting inspect on Chrome to access developer tools."></p>
<p>This will open the developer tools</p>
<p><img src="images/tutorials/styling_devtools1.png"
alt="Screenshot of the Chrome developer tools."></p>
<p>At the top, you can see the element that we have currently selected--the paragraph
with the arial font.</p>
<p>If we want to experiment with further changes, we can just click in the
.demo_font_arial box and start to modify it:</p>
<p><img src="images/tutorials/styling_devtools_2.png"
alt="Screenshot of the Chrome developer tools."></p>
<p>The developer tools are very helpful because they give us suggestions about what we
might modify. For example, if you start typing "font", you will get the following
suggestions:</p>
<p><img src="images/tutorials/styling_devtools_3.png"
alt="Screenshot of the Chrome developer tools autocomplete suggestions."></p>
<p>If we want to make the paragraph bold, we can use <code>font-weight: bold;</code></p>
<p><img src="images/tutorials/styling_devtools_4.png"
alt="Screenshot of the Chrome developer tools with bolded text."></p>
<p>And voila, our text is now bold.</p>
<p>Note that all of the changes made in the developer tools are temporary. They will
vanish when you reload the page. If you want them to persist, you need to make the
same changes to your css file:</p>
<p>
<code>.font_arial { <br/>
font-family: arial, sans-serif;<br/>
font-weight: bold<br/>
}
</code>
</p>
<p>That should get you started with CSS styling. Have fun exploring!</p>
</div>
</body>