At the end of this Tutorial you will be able to:
You can view a finished version of this project by clicking the image below.
In HTML, every element on a web page can be considered as a ‘box’. The words ‘box model’ are used when describing the design and positioning of elements.
In the box model, every HTML can be viewed as containing the following items:
For padding, borders and margins, you can use the same value for all four box edges, or assign different values to each individual edge.
In this Tutorial you will work with these two files:
First, let’s edit the HTML file from your previous Lesson:
<title>Responsive web page with highlighted boxes</title>
<meta name="description" content="A sample responsive web page with examples of text in highlighted boxes.">
<link rel="stylesheet" href="base-6.css">
<div class="important-note-1">
<h3>Important Note</h3>
<p>The text below contains important information for grant applicants and for other parties to their grant applications. This document will be updated to reflect any changes in legislation.</p>
</div>
You are now ready to work with your new web page (base-6.html) and stylesheet (base-6.css).
Before continuing, you need to add the box-sizing: border-box rule to the browser resets section at the top of your CSS file:
/* ==== BROWSER RESETS ==== */
* { padding: 0; margin: 0; border: 0; box-sizing: border-box; font-weight: normal; font-size: 16px }
body, html { height: 100% }
body { max-width: 1600px; margin: 0 auto }
Follow the steps below to use the <div>...</div> tag for adding samples of 'boxed' text to your base-6.html file.
<div class="important-note-1">
<h3>Important Note</h3>
<p>The text below contains important information for grant applicants and for other parties to their grant applications. This document will be updated to reflect any changes in legislation.</p>
</div>
Follow these steps to add a range of CSS styles to the four samples of boxed text in your HTML file.
/* ==== TEXT BOXES ==== */s
.important-note-1 {
margin: 42px 0 42px 0;
padding: 14px 14px 14px 14px;
border-style: solid;
border-width: 1px
}
.important-note-1 h3 { margin-top: 0 }
.important-note-1 p { margin-bottom: 0 }
.important-note-2 {
margin: 42px 0 42px 0;
padding: 14px 0 14px 0;
border-style: solid;
border-top-width: 8px;
border-bottom-width: 4px;
border-left-width: 0;
border-right-width: 0
}
.important-note-2 h3 { margin-top: 0 }
.important-note-2 p { margin-bottom: 0 }
.important-note-3 {
margin: 42px 0 42px 0;
padding: 14px 14px 20px 14px;
border-style: solid;
border-top-width: 0;
border-bottom-width: 0;
border-left-width: 20px;
border-right-width: 0
}
.important-note-3 h3 { margin-top: 0 }
.important-note-3 p { margin-bottom: 0 }
.important-note-4 {
margin: 42px 0 42px 0;
padding: 14px 14px 24px 14px;
border-style: solid;
border-width: 3px;
border-radius: 10px
}
.important-note-4 h3 { margin-top: 0 }
.important-note-4 p { margin-bottom: 0 }
Before you validate your web page and upload it to GitHub, ensure the following details are correct within the <head> of your base-6.html file.
To check the HTML in your web page is correct or valid, use the official W3C Markup Validation Service as follows.
To check your CSS is correct, use the official W3C CSS Validation Service. Follow these steps.
After validating your web page and stylesheet, you are now ready to upload them to your account on GitHub.
Your web page is now published on GitHub at a web address similar to the following, where username is the username you have chosen for your GitHub account:
https://username.github.io/base-6.html
It may take a few minutes for your uploaded file to appear on GitHub.
Introduction to the CSS basic box model
From the Mozilla Developer Network
CSS box model
From Interneting is Hard
CSS 101: The box model
by Nesha Zoric on dev.to
The CSS box model: How to use it correctly
by Nick Schäferhoff on Torque Mag
Video: Learn CSS box model in eight minutes
From Web Dev Simplified
Video: CSS box model tutorial
From W3Schools
Video: The CSS box model – margin, borders and padding explained
By Kevin Powell
Return to Contents.