At the end of this Tutorial you will be able to:
You can view finished versions of the three sample web pages you will create in this Tutorial by clicking the links below. The finished samples will each open in a new tab of your web browser.
You will also update your website home web page with hyperlinks to your three new sample web pages.
Working with your sample web page
The red border technique for visualising divs
Editing with your CSS stylesheet
Controlling the vertical spacing between container blocks
Working with your second sample web page
Working with your third sample web page
Alternating font colours between container blocks
Using a linear colour gradient as a background
In web design, the word section is used to describe a typically vertical sub-division of content in a web page. Usually, all sections are equally important. They are sub-divided for one reason only: to make them more inviting and easier to read.
In this Tutorial, you will create and style three examples of web pages with vertical sections. In each case, the sections will have two alternating background colours.
In this Tutorial you will work with these files:
You downloaded and unzipped these three files in the previous Introduction to the Box Model Tutorial.
Display the page-10.html web page in your Chrome or Mozilla Firefox Developer Edition browser. It should look as shown below.
You are now ready to work with your first sample web page that will contain sections.
The placing of a thin, red-coloured border around <div> elements is a common technique or ‘hack’ used by designers to help them view the layout of <div> boxes in the web browser.
Follow these steps to add some standard layout spacing to your content block divs.
/* container for web page blocks */ .container-block { border: solid 1px red; padding: 50px 18% 50px 18%; }
In the next few steps, you will add some new classes to create different background styles for your web page.
/* Coloured backgrounds */ .bg-hero-block { background-color: #f5f9fb } .bg-pastel-1 { background-color: #BEC7B4 } .bg-pastel-2 { background-color: #DEE2D9 } }
One problem remains with your web page: there is more vertical spacing below the content of your container blocks than above them.
This does not look right
A more professional and visually pleasing web page would have equal vertical spacing at the top and the bottom of the content within the container blocks. See below.
The extra vertical spacing at the bottom of your container-block <div> elements is the result of the margin-bottom value of the <p> paragraph tag.
margin-bottom: 20px;
You could delete this CSS style rule from the p paragraph styles. Then your paragraphs would have a margin-bottom value of zero, as set out in the web browser resets at the top of your stylesheet file.
Unfortunately, there would be no vertical spacing between <p> paragraphs of text within your container blocks. See below.
A more correct solution is as follows:
/* Last paragraph at bottom of container block */ .container-block p:last-child { margin-bottom: 0 }This new style applies only to the final paragraph within a container-block. No other paragraphs of text will be affected.
/* Last content item at bottom of container block */ .container-block *:last-child { margin-bottom: 0 }
Click page-10.html to view a finished sample of this web page in a new tab of your web browser.
To begin this second sample exercise, open these two files in VS Code:
Next, follow the steps below:
<title>Sample of content container blocks with altenating dark styles</title> <meta name="description" content="Using full-width divs to create a web page of alterating block containers with dark backgrounds.">
<link rel="stylesheet" href="style-11.css">
<!-- Google Fonts --> <link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=PT+Sans&display=swap" rel="stylesheet">
Next, let’s perform some style updates in the stylesheet file, style-11.css.
font-family: 'Roboto Condensed', sans-serif;
font-family: 'Roboto Condensed', sans-serif;
font-family: 'Roboto Condensed', sans-serif;
font-family: 'PT Sans', sans-serif;
color: #3e414f;
color: #000000;
color: #e1f5fe;
color: #fff;
letter-spacing: 8px;
letter-spacing: 4px;
text-transform: uppercase;
text-transform: uppercase;
/* Coloured backgrounds */ .bg-dark-1 { background-color: #000000 } .bg-dark-2 { background-color: #3e414f }You do not need to change the class name or the background-color value of the .bg-hero declaration.
Click page-11.html to view a finished sample of this web page in a new tab of your web browser.
To begin the third sample exercise, open these two files in VS Code:
Next, follow the steps below:
<title>Sample of container blocks with altenating light and dark styles</title> <meta name="description" content="Using full-width divs to create a web page with alterating light and dark background coloured container styles.">
<link rel="stylesheet" href="style-12.css">
<!-- Google Fonts --> <link href="https://fonts.googleapis.com/css2?family=Fira+Sans&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Arvo&display=swap" rel="stylesheet">
Next, let’s perform some style updates in the stylesheet file, style-12.css.
font-family: 'Fira Sans', sans-serif;
font-family: 'Fira Sans', sans-serif;
font-family: 'Fira Sans', sans-serif;
font-family: 'Arvo', sans-serif;
color: #1435b3;
color: #696969;
color: #000;
color: #2F4F4F;
letter-spacing: -3px;
letter-spacing: -3px;
/* Coloured backgrounds */ .bg-blue-light { background-color: #d8f0f5 } .bg-blue-dark { background-color: #1435b3 }You do not need to change the class name or the background-color value of the .bg-hero declaration.
We still have some more work to do with this third sample web page and stylesheet.
Follow these steps:
/* Light blue background: h3 sub-headings and p text paragraphs */ .container-block.bg-blue-light h3 { color: #1435b3 } .container-block.bg-blue-light p { color: #000 } /* Dark blue background: h3 sub-headings and p text paragraphs */ .container-block.bg-blue-dark h3 { color: #fff } .container-block.bg-blue-dark p { color: #fff }By ‘joining’ the two class selectors of .container-block and .bg-blue-dark together without any empty space between them, you are telling the web browser: only apply the h3 or p style rules that follow when the container <div> block in the web page has both classes. Similarly, the h3 or p style rules that follow the .container-block.bg-blue-light combination will apply only to container <div> blocks in the web page that have both these classes.
All done.
In all three sample web pages above you have applied what are called solid background colours to your container <div> blocks, using the background-color style property.
CSS also offers a property called background-image that enables you to apply linear gradients to <div> blocks and other web page elements.
Linear-gradients are of two main types:
Let’s apply a linear gradient background to our third sample web page.
.bg-blue-dark { background-color: #1435b3 }
/* Default gradient direction: top to bottom */ .bg-blue-dark { background-image: linear-gradient(#0575e6, #1435b3) }
/* Gradient direction: left to right */ .bg-blue-dark { background-image: linear-gradient(90deg, #0575e6, #1435b3) }
Click page-12.html to view a finished sample of this web page in a new tab of your web browser.
Here are some more examples of linear gradients for you to experiment with in your web pages.
/* Green */ background-image: linear-gradient(90deg,#02727e,#06b294);
/* Bronze */ background-image: linear-gradient(90deg,#6b2d38,#cd6065);
/* Purple to orange - modern */ background-image: linear-gradient(90deg,#e052a0,#f15c42);
/* Purple (AIB Bank) */ background-image: linear-gradient(90deg,#802b7b,#de0a85);
/* Blue (Disney Channel ad) */ background-image: linear-gradient(90deg,#07092f,#165cc0);
/* Yellow to blue - tangy! */ background-image: linear-gradient(90deg,#b8ea0a,#50c8f7);
Now that you have created and styled three new sample web pages, you need to add new hyperlinks to the home page of your web site.
<p><a href="websites/page-10.html">Web Page with Pastel Sections</a></p> <p><a href="websites/page-11.html">Web Page with Dark Sections</a></p> <p><a href="websites/page-12.html">Web Page with Alternating Sections</a></p>
Save your index.html web page and view the result in your browser.
After you have finished working with your files, you are ready to upload them to your account on GitHub.
Your web pages will be published at web addresses similar to the following:
https://username.github.io/index.html
https://username.github.io/page-10.html
https://username.github.io/page-11.html
https://username.github.io/page-12.html
It may take a few minutes for your uploaded files to appear on GitHub.
Return to Contents.