You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-6Lines changed: 60 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ In this tutorial, we'll actually be employing _three_ CSS files: normalize.css (
49
49
50
50
I'll begin by creating my **jeffstrap.css** file, and setting up some commented-out section heads to help organize it. Here's how it looks at first:
51
51
52
-
```html
52
+
```css
53
53
/* jeffstrap.css */
54
54
55
55
/* RESETS */
@@ -69,7 +69,7 @@ I'll begin by creating my **jeffstrap.css** file, and setting up some commented-
69
69
### Resets
70
70
In this section, we'll add style rules that fix a few things that browsers do to render pages oddly or inconsistently. This includes setting the document to size block elements, including the header, main, footer and any divs, using border-box sizing, instead of the frustrating default, content-box. We'll also set all margins and padding to 0, since different browsers use different defaults for these properties. When we want margins or padding, we'll add them explicitly.
71
71
72
-
```html
72
+
```css
73
73
/* RESETS */
74
74
75
75
html { box-sizing: border-box; }
@@ -85,7 +85,7 @@ html { box-sizing: border-box; }
85
85
### Design Styles
86
86
Design styles apply throughout the website, across all pages and in all sections; they determine the look of the app. Here, we'll set our font choices, as well as the colors for everything in the site. Fonts and colors are all we need to change to completely alter the styling from one project to the next. By pulling those rules together at the top of the file, we make it easy to make changes.
87
87
88
-
```html
88
+
```css
89
89
/* DESIGN STYLES */
90
90
91
91
/* Fonts */
@@ -112,10 +112,18 @@ header, footer {
112
112
}
113
113
114
114
a:link,
115
-
a:visited { color: #c00; } /* darker contrasting color for inactive links */
115
+
a:visited {
116
+
color: #c00; /* darker contrasting color for inactive links */
117
+
font-weight: bold;
118
+
text-decoration: none;
119
+
}
116
120
117
121
a:hover,
118
-
a:active { color: #f22; } /* brighter contrasting color for active links */
122
+
a:active {
123
+
color: #f22; /* brighter contrasting color for active links */
124
+
font-weight: bold;
125
+
text-decoration: none;
126
+
}
119
127
120
128
```
121
129
@@ -127,4 +135,50 @@ We'll be using Google Fonts to serve our chosen fonts; we set that up in the **\
127
135
#### Colors
128
136
We're using a deliberately simple color scheme here—four shades of gray for our backgrounds and font colors, and a contrasting red for links, chosen because it stands out well against both light and dark shades of gray. Since the logo **\<h1>** in the header is also a link, it will automatically be styled with the contrasting color, helping it grab the user's attention.
129
137
130
-
If red is too bold a choice for the contrasting color, try two shades of turquoise, gold, blue, green, or even pink. Just be sure that both shades contrast well with both the light and dark shades in your background. Readability trumps aesthetics for an MVP.
138
+
If red is too bold a choice for the contrasting color, try two shades of turquoise, gold, blue, green, or even pink. Just be sure that both shades contrast well with both the light and dark shades in your background. Readability trumps aesthetics for an MVP.
139
+
140
+
Note also that we set the font-weight and text-decoration properties for links (**\<a>** tags) here. This means that all links will appear in bold-face type, but without underlines, for a cleaner, more modern look than the default, underlined link style.
141
+
142
+
### Header Styles
143
+
In this section, we'll set up the rules for the elements in our **\<header>** section. It is here that we see the flexibility of our type-based CSS selectors coming into play.
144
+
145
+
```css
146
+
header { padding: 1rem; }
147
+
148
+
headerh1 { font-size: 3rem; }
149
+
150
+
headernavul { list-style: none; }
151
+
152
+
headernavli {
153
+
display: inline-block;
154
+
padding-left: 1rem;
155
+
border-left: 3pxsolid#888; /* medium gray */
156
+
}
157
+
158
+
headernavli:first-child { border-left: 0;}
159
+
160
+
headernavinput[type="submit"] {
161
+
overflow: visible;
162
+
text-align: center;
163
+
font-weight: bold;
164
+
width: auto;
165
+
border: none;
166
+
background-color: #222; /* dark gray */
167
+
color: #c00; /* darker contrasting color */
168
+
}
169
+
170
+
headernavinput[type="submit"]:hover,
171
+
headernavinput[type="submit"]:active {
172
+
color: #f22; /* brighter contrasting color */
173
+
}
174
+
```
175
+
176
+
The first rule just puts 1rem of padding around all four sides of the header, to keep the text from banging against the edges. I prefer rems ("root ems")for most CSS measurements because they scale most smoothly if you make the site responsive. By default, 1rem = 16 pixels; if you want to change that value, just set a font-size property to a value other than 16 pixels in the style for the root element, **\<html>**. If you later change the root em value, then every font-size or element dimension that is sized in rems will scale with the root em.
177
+
178
+
In the next rule, we specify any and all **\<h1>** elements in the **\<header>** should be rendered at a size of 3rems. Our CSS selector for the rule, "header h1", won't touch **\<h1>**s in any other element of the app—for example, an **\<h1>** in the **\<main>** element will be displayed at its default size, not at the 3rems specified in this rule.
179
+
180
+
The rest of the styles in the Header Styles section deal with the components of the header's **\<nav>** element. To be sure that we don't affect list or nav elements elsewhere in the app, we begin each selector with a mention of both the **\<header>** and the **\<nav>** types. The "header nav ul" rule eliminates the bullet points that appear by default on unordered lists. The "header nav li" rule changes the links in the nav bar to appear on a horizontal line, instead of as a vertical list; the "border-left" property establishes a vertical border between each pair of links. The "header nav li:first-child" rule _turns off_ that border to the left of the first link on the nav bar.
181
+
182
+
The remaining rules, which deal with "header nav input[type="submit"]" elements, are necessary because HTML and Sinatra all but require the "logout" link to be created as a button. Since ending the current session requires a POST route with a hidden "delete" object, it must be created as a single-button form, rather than as a simple link. The last few rules in the Header Styles section are necessary to remove the border and background from the button, so that it looks and behaves like the other links in the nav bar.
183
+
184
+
If you change the colors for the app in the Design Styles section, be sure to make the corresponding changes to the links here in the header nav bar. For this reason, it's a good idea to include my comments pointing out color properties in your CSS file.
0 commit comments