Skip to content

Commit 790291d

Browse files
committed
Add Header Styles section
1 parent 7528625 commit 790291d

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

README.md

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ In this tutorial, we'll actually be employing _three_ CSS files: normalize.css (
4949

5050
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:
5151

52-
```html
52+
```css
5353
/* jeffstrap.css */
5454

5555
/* RESETS */
@@ -69,7 +69,7 @@ I'll begin by creating my **jeffstrap.css** file, and setting up some commented-
6969
### Resets
7070
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.
7171

72-
```html
72+
```css
7373
/* RESETS */
7474

7575
html { box-sizing: border-box; }
@@ -85,7 +85,7 @@ html { box-sizing: border-box; }
8585
### Design Styles
8686
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.
8787

88-
```html
88+
```css
8989
/* DESIGN STYLES */
9090

9191
/* Fonts */
@@ -112,10 +112,18 @@ header, footer {
112112
}
113113

114114
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+
}
116120

117121
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+
}
119127

120128
```
121129

@@ -127,4 +135,50 @@ We'll be using Google Fonts to serve our chosen fonts; we set that up in the **\
127135
#### Colors
128136
We're using a deliberately simple color scheme here&mdash;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.
129137

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+
header h1 { font-size: 3rem; }
149+
150+
header nav ul { list-style: none; }
151+
152+
header nav li {
153+
display: inline-block;
154+
padding-left: 1rem;
155+
border-left: 3px solid #888; /* medium gray */
156+
}
157+
158+
header nav li:first-child { border-left: 0;}
159+
160+
header nav input[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+
header nav input[type="submit"]:hover,
171+
header nav input[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&mdash;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

Comments
 (0)