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
+29-27Lines changed: 29 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ I'll begin by creating my **jeffstrap.css** file, and setting up some commented-
65
65
```
66
66
67
67
### Resets
68
-
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.
68
+
In this section, we'll add style rules that fix a few ways that different browsers 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.
69
69
70
70
```css
71
71
/* RESETS */
@@ -92,11 +92,11 @@ h1, h2, h3, h4, h5, h6, p {
92
92
93
93
In the **body** rule, we first set the left and right **margin** to **auto**, so that the app content will be centered on the page. We'll also set **min-width** and **max-width** values to keep our page within a range in which our styling works. If you want a fully-responsive site, you'll need to add media queries—but that's a separate talk.
94
94
95
-
Finally, in the "Resets" section, we'll add a bottom margin of 0.5rem, to put just a bit of vertical whitespace between elements on the page. (I'll talk more about rems in section on header styles, below.)
95
+
Finally, we'll add a bottom margin of 0.5rem to our headers and paragraphs, to put just a bit of vertical whitespace between elements on the page. (I'll talk more about rems in section on header styles, below.)
96
96
97
97
98
98
### Design Styles
99
-
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.
99
+
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 look from one project to the next. By pulling those rules together at the top of the file, we make it easy to make changes.
100
100
101
101
```css
102
102
/* DESIGN STYLES */
@@ -136,11 +136,15 @@ main {
136
136
```
137
137
138
138
#### Colors
139
-
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 which stands out well against both light and dark shades of gray. Even so, there are several CSS rules that need to include color properties, so this section _looks_ kind of long. Thats because I've moved _all_ the rules which specify color to this section, for ease of maintenance. This probably isn't how you'd set up a stylesheet for the production version, but it makes this quick-and-dirty stylesheet easier to change.
139
+
We're using a deliberately simple color scheme here—four shades of gray for our backgrounds and font colors, and a red for links which contrasts well with both light and dark shades of gray. Even so, there are several CSS rules that need to include color properties, so this section _looks_ kind of long. That's because I've moved _all_ the rules which specify color to this section, for ease of maintenance. This probably isn't how you'd set up a stylesheet for the production version, but it makes this quick-and-dirty stylesheet easier to modify.
140
140
141
-
The **html** and **body** rules set up the background-color and font color for the site. The **html** background is a medium shade that contrasts with both the dark color of the **header** and **footer**, and the light shade in the **main** element. I've added the **header nav input[type="submit"]** selector to the **body** rule, since we will want the background color for the "Logout" button on our nav bar to match the surrounding header. More on the "Logout" button in the "Header Styles" section, below.
141
+
The **html** and **body** rules set up the background-color and font color for the site. The **html** background is a medium shade that contrasts with both the dark color of the **header** and **footer**, and the light shade in the **main** element. The **body** rule assigns a near-black gray as the background, and a near-white gray as the font color. These colors will appear in everything _except_ the **\<main>** element, which is to say the **\<header>** and **\<footer>** elements. I've added the **header nav input[type="submit"]** selector to the **body** rule, since we will want the background color for the "Logout" button on our nav bar to match the surrounding header. More on the "Logout" button in the "Header Styles" section, below.
142
+
143
+
The **main** rule sets the light background and dark font color for the **\<main>** element, which includes everything _except_ the **header** and **footer** of the app.
142
144
143
145
```css
146
+
/* Colors, con't. */
147
+
144
148
a:link,
145
149
a:visited,
146
150
headernavinput[type="submit"] {
@@ -169,14 +173,11 @@ main td {
169
173
170
174
```
171
175
172
-
173
-
174
-
The **main** rule sets the light background and dark font color for everything except the **header** and **footer** of the app.
175
-
176
176
The next two rules, which start with **a:link** and **a:hover**, style the links throughout the page. The first rule, for inactive links, assigns a rich, dark red which contrasts nicely with both the light and dark backgrounds in the site. This rule also sets link text to bold, with no underline; these properties are inherited by active links as well. The second link rule highlights active links a vivid red, which is noticeably brighter than the dark red of the inactive links. The other selectors in these rules, which include **input[type="submit"]**, style the "Logout" button to use the same colors as other links.
177
177
178
178
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. 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.
179
179
180
+
The last rule in the "Colors" section assigns the colors for any tables that are included in the **\<main>** element. The table borders should be the same color as the **background-color** of the **body**; the background-color for the table elements should be a shade lighter than the **\<main>** background, so that it stands out on the page.
180
181
181
182
### Header Styles
182
183
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.
@@ -208,14 +209,8 @@ header nav input[type="submit"] {
208
209
font-weight: bold;
209
210
width: auto;
210
211
border: none;
211
-
background-color: #222; /* dark gray */
212
-
color: #c00; /* darker contrasting color */
213
212
}
214
213
215
-
headernavinput[type="submit"]:hover,
216
-
headernavinput[type="submit"]:active {
217
-
color: #f22; /* brighter contrasting color */
218
-
}
219
214
```
220
215
221
216
#### header
@@ -227,24 +222,26 @@ In the **header h1** rule, we specify any and all **\<h1>** elements in the **\<
227
222
#### header nav
228
223
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.
229
224
230
-
The **header nav li** rulechanges 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.
225
+
In the **header nav li** rule, **display: inline-block;**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, and the **header nav li:first-child** rule _turns off_ that border for the first link on the nav bar.
231
226
232
227
#### header nav input[type="submit"]
233
-
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 is usually 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.
234
-
235
-
**Color Note:** 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.
228
+
The last rule in this section, which styles **header nav input[type="submit"]** elements, is 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 input to carry the "delete" action, it is usually created as a single-button form, rather than as a simple link. This rule removes the border and background from the button, so that it looks and behaves like the other links in the nav bar; recall that we set the colors for this input in the "Colors" section, above.
236
229
237
-
**Performance Note:**Selectors like this one, that depend on an attribute of an html tag, are just about the slowest possible CSS selector. We use them here because we are deliberately trying _not_ to have to add classes to our html file; in the deployed version of the app, you'd be better off to use a class as a selector, even if it's unique.
230
+
**Performance Note:**A selector like this one, that depends on the value of an attribute of an html tag, is just about the slowest possible CSS selector. We use it here because we are deliberately trying _not_ to have to add classes to our html file; in the deployed version of an app, you'd be better off to use a class as a selector, even if it's only used that once.
238
231
239
232
### Main Styles
240
-
In **main** styles section, we see our type-based selectors really pay off: they let us write an unlimited number of pages, partials, and forms which look decent (not great, but decent) with absolutely zero time spent on styling. Again, I'll show you the basic CSS code first, then break it down rule by rule.
233
+
In **main** styles section, we see our type-based selectors really pay off: they let us write an unlimited number of pages, partials, and forms which look decent (maybe not great, but certainly decent) with absolutely zero time spent on styling. Again, I'll show you the basic CSS code first, then break it down rule by rule.
241
234
242
235
```css
236
+
/* MAIN STYLES - Yield Block */
237
+
243
238
main {
244
239
padding: 1rem;
245
240
clear: both;
246
241
}
247
242
243
+
/* Lists */
244
+
248
245
mainul { margin: 0auto1.5rem; }
249
246
250
247
mainulli {
@@ -253,13 +250,18 @@ main ul li {
253
250
font-size: 1.25rem;
254
251
}
255
252
253
+
/* Forms */
254
+
256
255
maininput {
257
256
display: block;
258
257
margin-bottom: 0.75rem;
259
258
width: 100%;
260
259
}
261
260
262
-
maininput[type="text"] { padding: 00.5rem; }
261
+
maininput[type="text"],
262
+
maininput[type="password"] {
263
+
padding: 00.5rem;
264
+
}
263
265
264
266
maintextarea {
265
267
width: 100%;
@@ -272,12 +274,12 @@ main input[type="submit"] { width: 12rem; }
272
274
```
273
275
274
276
#### main
275
-
The padding in the **main** rule just pushes the text in from the edges of the **main** element a little bit; we use rems instead of pixels here so that the width of the padding scales automatically. The **clear: both** property is necessary to clear out the floats we used in the header; again, this isn't how we'd do it in the production version of our app, but it works fine for this quick-and-dirty stylesheet.
277
+
The padding in the **main** rule just pushes the text in from the edges of the **main** element a little bit; we use rems instead of pixels here so that the width of the padding scales automatically with the fonts. The **clear: both** property is necessary to clear out the floats we used in the header; again, this isn't how we'd do it in the production version of our app, but it works fine for this quick-and-dirty stylesheet.
276
278
277
279
Headers, paragraphs and links in the **main** element use the defaults set in the Resets and Design Styles, so we generally don't need to add anything for them here. If you decide to increase the size of your headers from the default—and you very well might—do that in the Resets section of this stylesheet.
278
280
279
-
#### main ul and main ul li
280
-
Almost every index view in a Sinatra or Rails app is going to display some sort of list of objects in the data base, but the default presentation of unordered lists is very 1994. To bring our stylesheet into the current century, we'll set **list-style** to **none**, to eliminate the bullets. The **margin** properties are necessary to get the list back into the right spot once we've taken out the bullets. I like to set the font-size for list items to 1.25rem, because these lists tend to be pretty important on our pages, and we want them to be prominent.
281
+
#### Lists: main ul and main ul li
282
+
Almost every index view in a Sinatra or Rails app is going to display some sort of list of objects from the data base, but the default presentation of unordered lists is very 1994. To bring our stylesheet into the current century, we'll set **list-style** to **none**, to eliminate the bullets. The **margin** properties are necessary to get the list back into the right spot once we've taken out the bullets. I like to set the font-size for list items to 1.25rem, because these lists tend to be pretty important in our Sinatra apps, and we want them to be prominent.
281
283
282
284
#### Forms: main input and main textarea
283
285
Forms are also very common in Sinatra and Rails apps, but again, the default styling for them is generally pretty ugly and unfriendly. We'll handle this mostly by styling the form input elements.
@@ -288,9 +290,9 @@ First, we'll set the **display** property of **main input** elements to **block*
288
290
mainlabel { display: inline; }
289
291
```
290
292
291
-
The margins and padding we set for **input** and **textarea** elements add a bit of whitespace to the form, while setting the **width** of each to **100%** makes each field wide enough to display most input data without scrolling. Remember that **\<input>** elements can only display a single line of text. For this reason, you'll want to use a **\<textarea>** form element for any field where users will be entering more than a few words, such as blog posts or comments.
293
+
The margins and padding we set for **input** and **textarea** elements add a bit of whitespace to the form, while setting the **width** of each to **100%** makes each field wide enough to display most input data without scrolling. Remember that **\<input>** elements display only a single line of text. For this reason, you'll want to use a **\<textarea>** form element for any field where users will be entering more than a few words, such as a blog post or comment.
292
294
293
-
The **main input[type="submit"]** rule sets **Submit** buttons to 12rem, which is wide enough to display the full text on the button in most cases. If you need more space, just up the rem in this rule.
295
+
The **main input[type="submit"]** rule sets **Submit** buttons to 12rem, which is wide enough to display the full text on the button in most cases. If you need more space, just up the rem in this rule. Also, note that since we styled these buttons using **main** along with **input**, this rule does not effect the Submit button that we used to log out the user in the **header nav** element.
294
296
295
297
### Tables
296
298
If your app displays complex user or game data, you'll probably want to show it in a table. Here are the rules to add to your stylesheet to automatically style a simple table:
0 commit comments