Hello and welcome.
In the previous post, we did a simple test.
The correct HTML code for that is shown below;
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="my_site.css">
</head>
<body>
<h2 class="reds">NASA | JPL</h2>
<h1 class="blues">ON A MISSION</h1>
<h4 class="reds">PODCAST</h4>
<p id="underlined">A new podcast from NASA</p>
<ul>
<li>Arrival</li>
<li>We Are the World</li>
<li>Worlds of Wonder</li>
</ul>
<ol id="roman">
<li>NASA is cool</li>
<li>Coding comes second, arguably.</li>
<li>What is third place?!</li>
</ol>
<table >
<tr> <th class="blueBordered">Name</th> <th class="blueBordered">Title</th> </tr>
<tr> <td >John Doe</td> <td >Tutor</td> </tr>
<tr> <td >Jane Doe</td> <td >Student</td> </tr>
</table>
<img src="images/apollo.jpg" width="450px" height="450px" class="blueBordered">
<p id="greenItalic">Click <a href="https://relatableterms.blogspot.com/">me</a> to start learning code </p>
</body>
</html>
Be sure to compare your code with the one above and make any necessary corrections to your answer.
Let's move on to today's subject: imaginary boxes, borders, margins and padding.
Consider the following two boxes:
The left box has a blue border while that on the right has a green border.
The space outside the border is called the margin.
The top, right, bottom and left margins of the blue box are indicated by the red lines.
Similarly, the margins (top, right, bottom and left) of the green box are indicated by the yellow lines.
Each box has some text inside it (content).
The space from the border of a box to the text content is called the padding of the box.
The top, right, bottom and left padding of each box are indicated by the black lines.
Understanding the above, is important when arranging elements in html.
Each element can be thought of as a box, with a border (invisible by default), margins and padding.
To understand this, let's practice:
Note that these apply to all html elements (except the <head></head> section and everything that goes inside it) .
As always, here is a video that you can use to follow up on this tutorial.
Till next time, happy coding.
In the previous post, we did a simple test.
The correct HTML code for that is shown below;
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="my_site.css">
</head>
<body>
<h2 class="reds">NASA | JPL</h2>
<h1 class="blues">ON A MISSION</h1>
<h4 class="reds">PODCAST</h4>
<p id="underlined">A new podcast from NASA</p>
<ul>
<li>Arrival</li>
<li>We Are the World</li>
<li>Worlds of Wonder</li>
</ul>
<ol id="roman">
<li>NASA is cool</li>
<li>Coding comes second, arguably.</li>
<li>What is third place?!</li>
</ol>
<table >
<tr> <th class="blueBordered">Name</th> <th class="blueBordered">Title</th> </tr>
<tr> <td >John Doe</td> <td >Tutor</td> </tr>
<tr> <td >Jane Doe</td> <td >Student</td> </tr>
</table>
<img src="images/apollo.jpg" width="450px" height="450px" class="blueBordered">
<p id="greenItalic">Click <a href="https://relatableterms.blogspot.com/">me</a> to start learning code </p>
</body>
</html>
Be sure to compare your code with the one above and make any necessary corrections to your answer.
Let's move on to today's subject: imaginary boxes, borders, margins and padding.
Consider the following two boxes:
The left box has a blue border while that on the right has a green border.
The space outside the border is called the margin.
The top, right, bottom and left margins of the blue box are indicated by the red lines.
Similarly, the margins (top, right, bottom and left) of the green box are indicated by the yellow lines.
Each box has some text inside it (content).
The space from the border of a box to the text content is called the padding of the box.
The top, right, bottom and left padding of each box are indicated by the black lines.
Understanding the above, is important when arranging elements in html.
Each element can be thought of as a box, with a border (invisible by default), margins and padding.
To understand this, let's practice:
- Open Sublime Text and create a new file and name it 'arrangements.html' . Save the file.
- Create another file and name it 'arrangements.css'. Save this in the same location as the arrangements.html file.
- Open your html file and type in the following code inside the body tag: <p id="p1">Paragraph 1</p>
<p id="p2">Paragraph 2</p> - Link this html to the css file and save it.
- Open up the css file (arrangements.css) in Sublime text proceed as follows:
- First, type the following code, then save and open arrangements.html in your browser; #p1{
border: 1px solid black;
}
#p2{
border: 1px solid blue;
} - Notice that each of the paragraphs now has a border. Now change your css code to;
#p1{
border: 1px solid black;
padding-left: 12px;
}
#p2{
border: 1px solid blue;
padding-left: 12px;
} - Save and open up arrangements.html in your browser. Notice that the text inside each paragraph has been moved to the right a bit (12px). Experiment with the padding-left value by increasing it and decreasing it as you see fit, each time refreshing the site in your browser to see the results.
- We can move the text within the borders of each paragraph using text-align attribute. In your css, change the code to; #p1{
border: 1px solid black;
padding-left: 12px;
text-align: right;
}
#p2{
border: 1px solid blue;
padding-left: 12px;
text-align: center;
} - Save and refresh your site in the browser. Now the text on the first paragraph appears on the right and that of the second paragraph is centered.
- We can increase the space between the two paragraphs by changing their margins. First change your css to; #p1{
border: 1px solid black;
padding-left: 12px;
text-align: right;
margin-bottom: 64px;
} - Save and refresh your site in the browser. Notice that the second paragraph has been moved further down (by 64pixels) from the first paragraph than before. The above code has the same effect as changing the top margin of the second paragraph by 64px as; #p2{
border: 1px solid black;
padding-left: 12px;
text-align: right;
margin-top: 64px;
} - Experiment with margins by changing the margin-top, margin-left, margin-right and margin-bottom values of each paragraph. Each time, save and refresh your browser and take note of the changes.
- Now that you have understood what borders, margins and padding are. Let's finish up by changing the border and padding of another html element. the body itself. Change your css code to; body{
border: 1px solid red;
padding-top: 48px;
padding-right: 64px;
padding-left: 32px;
}
#p1{
border: 1px solid black;
padding-left: 12px;
text-align: right;
margin-bottom: 64px;
}
#p2{
border: 1px solid blue;
padding-left: 12px;
text-align: center;
} - Save and refresh the site in your browser.
Note that these apply to all html elements (except the <head></head> section and everything that goes inside it) .
As always, here is a video that you can use to follow up on this tutorial.
Till next time, happy coding.
Comments
Post a Comment