LESSON 3.11
Module 3 Template: Putting It All Together (Optional)
Pulling together the Module 3 template changes
Link a stylesheet, add a Google Font, and center the header, nav, main, and footer sections of your template.
Optional Lesson. This lesson walks through the template changes for Module 3. If you are taking CSCI1450 or BUS1880, these steps are part of your lab grade. If you are a self-directed learner, follow along to build a solid reusable template for your own projects. This lesson picks up on the template work in Lessons 2.1, 2.2, 2.6, 2.7, and 2.8. You can also find all the template instructions in the blog post.
By the end of Module 3 your website template should have a stylesheet attached, a Google Font loaded, and the major sections centered on the page. This lesson walks through each of those steps.
Step 1: Add style.css to Your Template Folder
If you have not already done this in Lesson 3.04, do it now.
- Open your text editor and create a new file.
- Use File → Save As to save it as
style.cssinside yourtemplatefolder. - Open your
template/index.htmlfile and add this line inside the<head>:
<link rel="stylesheet" href="style.css">
Step 2: Add a Google Font
If you have not already added a Google Font in Lesson 3.07, do it now. Choose an easy-to-read font like Roboto, Open Sans, Montserrat, or Lora.
- Go to fonts.google.com and select a font.
- Click Get Font, then Get Embed Code, and copy the
@importline. - Paste the
@importat the very top of yourstyle.cssfile. - Add the font to the body selector:
@import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');
body {
font-family: "Montserrat", sans-serif;
}
Use your own font name. The example above uses Montserrat.
Step 3: Center the Header
Add this to your stylesheet to center the content inside the header:
header {
text-align: center;
}
Step 4: Center the Navigation
nav {
text-align: center;
}
Step 5: Style the Main Section
On most websites the header, nav, and footer span the full width of the page, but the main content area has a maximum width to keep lines of text from getting too long to read comfortably.
main {
max-width: 1000px;
margin: 20px auto;
padding: 10px;
}
margin: 20px auto is shorthand for: 20px on the top and bottom, and auto on the left and right, which centers the element horizontally.
Step 6: Center the Footer
footer {
text-align: center;
}
Check Your Work
Open index.html in Chrome. Your page should have your Google Font applied throughout, the header and nav text centered, the main content centered with a max-width, and the footer text centered. Your template is now a solid starting point for every project going forward.
Note: We will keep adding to this template throughout the course. If you skipped any steps, go back and complete them now. Some CSS in later modules depends on the semantic elements and stylesheet being in place.
❓ Frequently Asked Questions
This lesson is marked optional for self-directed learners. The steps are useful for building a solid reusable template, but you can skip it and come back later if you prefer to keep moving through the lessons.
Just skip those steps. Each step says which earlier lesson it builds on, so if you attached your stylesheet in Lesson 3.04 or added a Google Font in Lesson 3.07, you are already ahead and can move on to the next step.
Full-width text is hard to read on large screens. Centering your content in a wrapper with a max-width keeps line lengths comfortable and gives your site a clean, professional look from the very beginning.
★ Key Takeaways
This lesson pulled together the template work from Module 3 into one place. You linked a stylesheet, added a Google Font, and centered the header, nav, main, and footer sections. These are the building blocks you will use on every project going forward.
Google Ads
The costs of this website are partially offset by revenue from Google Ads.Tools of the Trade
HTML/CSS Lessons
-
-
-
1.3. HTML Tag Preview
-
-
-
2.2. The HTML Framework
-
-
2.4. HTML Headings
-
-
-
-
-
-
3.01. Introduction to CSS
-
3.02. How CSS Cascades
-
-
-
-
3.05. CSS Colors
-
3.06. RGBA Colors
-
-
3.08. Font and Text Properties
-
3.09. Classes and IDs
-
-
-
-
-
4.3. HTML Embedded Images
-
-
-
-
-
-
5.1. CSS Borders
-
5.2. CSS Border Radius
-
5.3. CSS Gradients
-
5.4. CSS Box Shadows
-
5.5. CSS Text Shadows
-
7.1. The Display Property
-
-
-
7.4. The Box Model
-
-
-
-
-
-
9.1. Website Tables
-
9.2. HTML Forms
-
-
9.4. Special Form Fields
-
9.5. Embedding Multimedia
-
-
9.7. Keyboard Shortcuts
-
10.1. What Is a Framework?
-
10.2. Font Awesome Icons
-
-
10.4. Bootstrap Grid System
-
-
10.6. Bootstrap Navigation
-
-
11.2. Purchasing a Domain Name
-
11.3. Website Hosting
-
11.4. Nameservers and DNS
-
11.5. FTP
-
11.6. GitHub Pages
