HTML5 Authoring 5
HTML5 Authoring 5
Each element would appear in its own block-- because all heading tags are block elements.
You can see this illustrated using the Developer tools in Chrome.
enter image description here
The block for the <h2> tag here is in blue. The orange represents additional margin space
for the block. Note the block stretches all the way across the browser window.
If we were to look at an inline tag like <strong> the result would be different.
Let’s say we had the following code:
<p>The quick brown fox jumped over the
<strong>lazy dogs</strong>. Why? Who cares.</p>
If we were to take a look at the result with Chrome developer tools:
Typical for inline elements, the element only takes the space required by the content.
This can be confusing if you’re trying to debug-- Or just understand your code. I like to put
a quick remark next to each div closing tag so I know exactly what I’m closing. I’ll use the
single-line comment structure to do so as demonstrated in the code below.
</div> <-- Closing Hero Image -->
</div> <-- Closing Hero Box Header -->
</div> <-- Closing Main Header Area -->
</div> <-- Closing Container -->
Using this method, when I review the code I always know which logical division is being
closed.
Hiding Divs in Your Text Editor
If you’re using Brackets (most other text editors have a way to do do this as well), you’ll
notice a triangle next to our <div> tags. In the screenshot below, you’ll see it next to line 27:
This little triangle allows you to hide and restore the <div> element. This is designed to
hide unnecessary content in your text editor temporarily.
The id and class attributes are used to identify and/or group your logical divisions and
spans. In the code <div id="description">, the id uniquely identifies the logicial division.
In fact, in well coded HTML the value description could not be repeated in any other id.
It’s meant to be a unique identifier.
A class, on the other hand, is meant to create a group of elements. You might create a
class because you want a number of <span> elements to be formatted the same way. What
you’ll notice in the code above the class frame is used repeatedly in the code.
.frame
{
color: rgb(0,0,150);
font-weight: bold;
}
.first
{
font-family: Arial;
}
</style>
</head>
<body>
<h1><span class="frame">Framework</span>
Television</h1>
<div id="description">
<p><span class="first">Learn digital skills like
coding, design and app development with <span
class="frame">Framework</span> Television.</span>
</p>
Looking carefully at the CSS you’ll notice that we use different selectors than in previous
examples. If you want to style an element with an id attribute you use a # sign and the
value of the id as in #description. Any CSS will be applied to the logical division id’ed as
description.
Similarly class level CSS is identified with a period and the name of the class as in .frame
which will be applied to multiple elements in this case.
p
{
font-family: Arial;
font-size: 1.25em;
}
</style>
</head>
<body>
<div class="fact">
<h1>Fact #1</h1>
<p>Around 50% of all Wikipedia vandalism is
caught by a single computer program with more than
90% accuracy.</p>
</div> <!-- fact -->
<div class="fact">
<h1>Fact #2</h1>
<p>If there was a computer as powerful as the
human brain, it would be able to do 38 thousand
trillion operations per second and hold more than
3580 terabytes of memory.</p>
</div> <!-- fact -->
<div class="fact">
<h1>Fact #3</h1>
<p>The password for the computer controls of
nuclear tipped missiles of the U.S was 00000000
for eight years.</p>
</div> <!-- fact -->
<div class="fact>
<h1>Fact #4</h1>
<p>Approximately 70% of virus writers are said to
work under contract for organized crime syndicates.
</p>
</div> <!-- fact -->
</body>
</html>