![]() |
| ||
| |||
The <br> TagAs you typed text into the <body> of the last lesson, you probably noticed that line breaks made in the code did not break the line when your browser rendered the page. (A line break is made when you hit "Enter" as you're typing in a text editor. A new line is started.) Browsers ignore line-breaks in code. This is handy because we can use line-breaks to organize our code without it effecting the appearance of the rendered page. But, we do need to have a way to make line breaks. We have two tags to help us: the <p> and <br> tags. The <br> tag causes a single line break. The <br> tag is one of the few tags that does not have a closing tag. You just type "<br>" wherever you want a line break in your text. Open the page you made in the first lesson and try this:
<html> Notice that I didn't make any line breaks in the code. They don't matter to the browser. The browser is only rendering the line breaks defined by the <br> tags. See what it looks like when run in a browser here. In practice, it's easier to understand your code if you make one or two line breaks in the code when using these tags. These line breaks in the code have no effect when the page is rendered in a browser, but they make your code a little easier to keep up with. Tags make line breaks. Say we want a lot of lines between one line and another. Lets say five lines. We'll use the <br> tag to make as many line breaks as we need:
<html> Now view the page this code produces here. Using the <br> tag is a common way of making vertical "whitespace". Use the <br> tag to make any extra vertical whitespace you may need. Making ParagraphsThe <p> tag blocks text off into paragraphs by inserting two line breaks between separate blocks of text. It has a closing </p> tag. I suggest you use it, but others disagree. It will work in most cases if you just open a paragraph with the opening <p> tag and ignore the closing </p> tag. There can, however, be spacing problems in certain circumstances and using available closing tags is a good habit to get into. Try this in the <body> of your page:
<p>Roses are red.<br> Violets are blue</p> Check out what this page would look like here You'll notice that the text is now in two blocks with two line breaks after "blue". This is pretty much what the <p> tags do. They add the double line breaks. The <br> tag adds single line breaks (instead of two). There's also the conceptual difference that the <p> tags contain a block of content and the "unclosed" <br> tag merely causes an effect. This will be important later on. Remember to use the <br> tag to make extra line breaks, not the <p> tag. Only use the <p> tag set when you're going to put some content between the tags. Adding EmphasisWe add emphasis to a word or phrase by italicizing or making the letters bold. The tags to do this are really simple: <i> and </i> for italics, and <b> and </b> for bold. Using the sample we've started above (except I put everything in one paragraph - <p>), lets make the words "Roses" and "Violets" italicized and the phrase "my site" bold:
<html> Click here to see the page the new code makes. It will open in a separate window. Quoting Blocks Of TextNow for a couple of other ways to format blocks of text. First is the <pre> tag. The <pre> and </pre> tags tell the browser to render the content between them exactly as typed -- including extra spaces and line breaks. The element "pre" refers to pre-formatted text like something you copied from a text or document file. It also comes in handy when you have some odd formatting like if we chose to indent some of the lines of our current poem:
<html> Notice that I've put the poem between <pre> tags and that I've included some extra spaces and line breaks in the code. These extra spaces and line breaks will be rendered by the browser because they are between <pre> tags. See how the above code looks when rendered in a browser here. See? The extra spaces and line breaks in the code are now rendered and not ignored. The next tag used for presenting quoted material is the <blockquote> tag. This makes a neat effect that you're probably used to seeing in print media. It causes some extra margin space to the left of the content between the <blockquote> and <blockquote> tags. This makes the <blockquote> content appear as a more indented than the surrounding text in the rest of the page. For the example I'm going to code some regular paragraphs (<p>) and put a couple of <blockquote>s in between them so you can better see the effect:
<html> Click here to see how the above code would look in your browser. Notice the extra space at the left margin of the text inside the <blockquote> tags. This is how the <blockquote> offsets its content from the surrounding content on the page. Using <!-- Comments -->As your code gets longer and bulkier, you'll eventually need to put notes or "comments" in your code that won't show up when the page is rendered in a browser. These notes can help you find your way around your code and can be a real time saver. They also help to explain your code to other people reading it. You make a comment like this: <!-- Your comments will go here --> Just begin the comment with a "<" followed immediately (no space) by an exclamation point ( ! ) and two dashes ( - , minus signs). Now make a space (or not) and type in your comments. Close the <!-- comment --> tag with a space, two dashes and the ">" angle bracket. Here's what a comment looks like in your code:
<body> These comments will appear in your code, but not on your page when it's viewed in a browser. You can add this type of comment anywhere in your HTML code, but most comments are found in the <body>. Get used to adding comments to your pages early. They'll really help you find your way around your code. Practice making all of the effects above. To save you some typing, download some bulk text here. It is a zipped text file. It's the full tutorial I've written on how to use WinZip®. You can copy and paste sections of the text from it to save you a lot of time typing. Make sure to notice the differences between using <pre> tags and <blockquote>s. What's important at this point is that you know how to use the tags from this lesson to format any text. Make a single page with at least two examples of each of the above tags before moving on. I'd recommend making your basic code framework from lesson 1, paste in some of the bulk text from my WinZip® tutorial and then add tags as you see fit. Make sure to check your work in a browser frequently. Next we'll see how to make big, bold headlinesto title our page's sections and sub-sections. We'll also learn how to align text. |
|||
| |||