Hi, boys and girls! Is everyone ready for another adventure in the magical, fantastical Internet?
Yeah!
Well, all right!
This week we're going to learn how to take any HTML tag and bend it to our will. Do you remember how HTML tags work, boys and girls? Let's take a look at a standard image tag:
<img src="http://www.infernal-monologue.com/images/mfiBanner.gif" alt="Magical, Fantastical Internet banner" title="Ta-da! Rollover text!" height="300" width="400" />
It's always a good idea to define your heights and widths, kids, and the title is great for rollover text. And don't forget to add your alt text or
Angry Mr. Ada will get you! The image tag above should give us:

Now that we're reminded how an HTML tag works, let's look at two new tags: div tags and span tags. We'll start with div tags.
Did you notice up above, when I showed you the HTML code? Don't bother scrolling up, I'll recreate it down here:
<img src="http://www.infernal-monologue.com/images/mfiBanner.gif" alt="Magical, Fantastical Internet banner" title="Ta-da! Rollover text!" height="300" width="400" />
But that's a little too much to work with, isn't it, kids? Let's clean it up:
The quick brown fox jumped over the lazy dog.
Much better! Now let's take a look at how it works:
<div style="font-family: Courier New, Courier, mono; background-color: #B2B299; padding: 10px;">The quick brown fox jumped over the lazy dog.</div>
Wow. A lot to take it, right, boys and girls? Well, don't panic, we'll take it one step at a time.
First of all, you can see our actual text right at the end there, followed by the closing div tag. Nothing new there.
The new bit is the "style" attribute. This is what makes Cascading
Style Sheets work. You can use the style attribute to change darn near
anything about
any HTML tag.
Let's take a look at the "properties" - the first part of the style, before the colon - used. There's "font-family", which lets you choose and prioritize fonts; "background-color", which lets you change the color of the background; and "padding", which lets you set how much spacing you have between the text and the border.
The best part is that the properties are pretty self-explanatory. But the "values" of the properties are where the action's at.
I wanted the HTML example to look like the Create a Post area of Blogger, so I went with monospace fonts like Courier New and Courier. I wanted the background to be a slightly darker colour than than my normal background colour, and with a bit of tweaking I discovered that #B2B299 fit the bill nicely. And I wanted to make it as easy to read as possible, so I put 10px (or "pixels") worth of space between the text and the border.
But wait. We don't have a border, do we, boys and girls? Wanna make one?
Yeah!
Okay! We'll keep it simple, since this is the first time you all at home are adding a CSS property, but then we'll try a special project, okay?
So, since we want a border, what do you suppose the property is going to be? That's right, "border". To make it show up, we have to tell it what kind of border we want, like "solid". And what colour do we want to make the border? How about "red", keeping in the theme of this site? That leaves us with this:
border: red solid;
And we just add that to the style attribute we used earlier:
<div style="font-family: Courier New, Courier, mono; background-color: #B2B299; padding: 10px; border: red solid;">The quick brown fox jumped over the lazy dog.</div>
Hey, look at that! Nice job.

Now, as a special project, let's try to recreate a narration box from the latest issue of
Flash, the Fastest Man Alive. In it, the new Flash, Bart Allen, has specially colured narration boxes, like the one on the right.
What all do we have there? The actual text, of course. But it's red, on a yellow background, with a red border. Given that, we have:
<div style="color: red; background-color: yellow; border: solid red;">Besides, I've<br />always been a<br />bit... <span style="font-weight: bold;">impulsive</span>.</div>
Did you catch that? We just had the first appearance of the span tag! It's essentially the same as the div tag, but it can be used "inline" instead of changing an entire block of text. I also added line breaks so it will match the narration box. So now we've got:
Besides, I've
always been a
bit... impulsive.
Ew. Not exactly there yet, huh, kids? But it's a good start!
First we need to get rid of all that "white space" (okay, it's yellow, but it's
called white space). We need to adjust the width, don't we? But by how much? The image above is 171 pixels wide, so why don't we guess about... 150px?
Besides, I've
always been a
bit... impulsive.
Hey, look at that! Looks just about right. Let's see the code:
<div style="color: red; background-color: yellow; border: solid red; width: 150px;">Besides, I've<br />always been a<br />bit... <span style="font-weight: bold;">impulsive</span>.</div>
Next thing we need to do is center the text. Easy enough. The property is "text-align" and the value is "center".
Besides, I've
always been a
bit... impulsive.
Okay, good enough. Now we need to center the whole thing. The way to do that is to use the "margin" property and set it to "auto". The margin of the div is the space between the border and and whatever element the div is sitting in. Take a look:
Besides, I've
always been a
bit... impulsive.
There we go. Let's take another look at the code:
<div style="color: red; background-color: yellow; border: solid red; width: 150px; text-align: center; margin: auto;">Besides, I've<br />always been a<br />bit... <span style="font-weight: bold;">impulsive</span>.</div>
One last bit of fiddling. The border in the caption has a drop shadow effect that we can attempt to duplicate. All we need to do is divide the "border" property into four separate properties, "border-top", "border-right", "border-bottom", and "border-left". Like so:
<div style="color: red; background-color: yellow; border-top: solid red 2px; border-right: solid red 5px; border-bottom: solid red 5px; border-left: solid red 2px; width: 150px; text-align: center; margin: auto;">Besides, I've<br />always been a<br />bit... <span style="font-weight: bold;">impulsive</span>.</div>
Which is:
Besides, I've
always been a
bit... impulsive.
Hooray! I think we did it. Let's get a side-by-side:

Besides, I've
always been a
bit... impulsive.
Good work, boys and girls. If you want to know more, go to
W3Schools and go through their tutorial. Come back next time for Fun With Unicode!, right here on
The Magical, Fantastical Internet!Labels: The Magical Fantastical Internet