Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Saturday, December 10, 2011

HTML Tutorial: Paragraph Attributes

Last time, I posted a lesson on <p> or <P> for paragraph under Basic HTML Tutorial: Paragraphs and Texts, this time, we will go deeper into the attributes of <P>. Please read the previous tutorials by searching the site, it's filed under (tutorials). This way, you will be able to go along with us.

The <p> tag defines a paragraph (as discuss on last topic). The p element automatically creates some space before and after itself. The space is automatically applied by the browser, or you can specify it in a style sheet. However, we will be discussing about stylesheet later on, in the meantime, let's just focus on the attributes that does not rely on a stylesheet.

According to W3C, the <p> tag is supported in all major browsers including IE (Microsoft Internet Explorer), Mozilla Firefox, Opera, Google Chrome, and Apple Safari.

The Attributes

An attribute is a format or function you can apply on an element. In this case, on the <p> element or tag. It is written after the p for instance <p align="left">.

Align

On our last discussion about <p>, I have only taught how to display a text or paragraph using the default align format. The alignment by default is left or left aligned. However, using the align attribute, you can change the alignment of the text. You can designate the values: left, right, center, and justify. According to W3C, the align attribute is allowed in HTML 4.01/XHTML 1.0 DTD type webpages under Transitional and Frameset, however, is not accepted under Strict compliance, possibly because, it causes issues on some browsers.

Values:

left - the texts or paragraph aligns to the left of the page. If the words do not fit in a row, it is automatically move below, causing a break at the right column.
right - the texts or paragraph aligns to the right of the page. If the words do not fit in a row, it is atumatically move below, causing a break at the left column.
center - the texts or paragraph aligns at the center. The texts floats on the middle of the row.
justify - the texts or paragraph automatically adjust its spacing so that the paragraph is evenly fitted in every row.

Syntax:

<p align="x"> where x stands for the values. See the values above.

Example:

<html>
<head>
<title>Text Alignment</title></head>
<body>
<p align="left">The texts here are left aligned.</p>
<p align="right">The texts here are right aligned.</p>
<p align="center">The texts here are centered.</p>
<p align="justify">The texts here are justified. Observe that the words are being distributed evenly to fit the row. This is a sample. This is a sample. This is a sample. This is a sample. This is a sample. This is a sample. This is a sample. This is a sample.</p>
</body>
</html>

The output:

Click to enlarge

Class

Class stands for any classname matching on the stylesheet. It calls its format from a stylesheet. Class is a standard attribute for <p>, meaning, all browsers support it. We will discuss more on this later on.

Syntax:

<p class="x"> where x is a corresponding name found in the stylesheet. It could be any name (user-specific).

Direction

The attribute use is dir. It specifies the direction of the text. ie. from left to right or right to left. It is a standard attribute and resembles the left or right align attributes.

Values:

rtl - (right to left) text is right aligned and moves toward the left. Similar to align="right".
ltr - (left to right) text is left aligned and moves toward the right. Similar to align="left".

Syntax:

<p dir="x"> where x can be "rtl" or "ltr". See values above.

ID

ID is similar to class in that it also looks for a corresponding id name in the stylesheet. It specifies a unique id for an element. This is also a standard attribute, meaning, it is recognized by all browsers.

Syntax:

<p id="x"> where x is any user-specified name in the stylesheet, which usually begin in a #.

Language

Specifies a language code for the content in an element. This has no effect on the graphical side other than to assist search engines and browsers in use. There are numerous language you can use on this attribute but to name a few, see values below:

Values:

en - English
tl - Tagalog
sd - Sindhi
la - Latin
ja - Japanese
zh - Chinese

We will provide a list for this one, later on...

Syntax:

<p lang="x"> where x is an abbreviation of a language code. W3C has a list for them.

Style

Specifies an inline style for an element. The style attributes used in this attribute is similar to the ones used in the sylesheet or CSS (Cascading Stylesheet). However, instead of calling a format from a stylesheet, you can directly set the property within the p element itself; even without requiring a stylesheet. There are numerous stylesheet properties you can use to directly give the text a style. A few example of the values are shown below:

Values:

color: - to specify the font's color. It must be terminated by a ; [ie. red, blue, #000000, rgb(255,255,255)]
font-size: - to specify the font's size. It must be terminated by a ; [ie. small, medium, large, x-large, xx-large, smaller]
font-weight: - determines how thin or thick characters in text should be displayed. It must be terminated by a ; [ie. bold, normal, bolder, lighter, 100, 500, 700]

We will go deeper into this once we study CSS.

Syntax:

<p style="x"> where x is a value of a Stylesheet property.

Example:

<html>
<head>
<title>Text</title></head>
<body>
<p style="color: red;">Text</p>
</body>
</html>

Output:



or we can also combine a set of stylesheet properties to give the text additional styles. For example:

<html>
<head>
<title>Text</title></head>
<body>

<p style="color: rgb(215,60,56); font-weight: bolder; font-size: medium;">Text</p>

</body>
</html>

Output:



Title

This specifies extra information about an element. When you move the mouse pointer over a text, the title specified on the text will display.

Syntax:

<p title="x"> where x can be any word or sentence, or paragraph (user-specific).

Example:

<html>
<head>
<title>Text</title></head>
<body>
<p title="A Dragon is a mythical giant lizardlike creature that breaths fire.">Dragon</p>
</body>
</html>

Output:



XML Language

Specifies a language code for the content in an element, in XHTML documents. This is similar to Language attribute only that this one is use in an XHTML document or page.

Syntax:

<p xml:lang="x"> where x may contain a language code.

Event Attributes

These attributes requires a javacript command in order to work. Since javascipt is out of our topic, I am simply going to give all the event attributes that can be use with the p element. Note that these attributes requires advance javascript understanding, it provides special features or effects not normally provided in HTML.

onclick - Script to be run on a mouse click.
ondbclick - Script to be run on a mouse double-click.
onmousedown - Script to be run when mouse button is pressed and hold down.
onmousemove - Script to be run when mouse pointer moves.
onmouseout - Script to be run when mouse pointer moves out of an element.
onmouseover - Script to be run when mouse pointer moves over an element.
onmouseup - Script to be run when mouse button is released.
onkeydown - Script to be run when a key is pressed and hold down.
onkeypress - Script to be run when a key is pressed and released.
onkeyup - Script to be run when a key is released.

Example:

<p onmouseover="x"> where x is a javascript command.


That's all for today. Now, go and practice.

For an exercise, how about creating this page.


Goodluck!

Monday, December 5, 2011

Basic HTML Tutorial: Paragraphs and Texts

Welcome to the third session of our Basic HTML Tutorial. The last two Tutorials I've discussed are below:

Basic HTML Tutorial
Basic HTML Tutroial: Background Colors

The first is an introductions to HTML, while the second is about setting background colors on pages.

This time, we go into paragraph or texts. These are, of course, the texts that you read on a web page. Here, I'm going to teach you how to display texts inside a page. Let's begin...

Note: If you don't know how to create a web page, read the first lesson first (Basic HTML Tutorial).

The element used by HTML to display a text is <p> or <P>, where "p" is for paragraph. Every browser usually does not need <p> in a web page to display a text; any texts entered within the <body>, except for elements, is automatically treated as paragraph. For example:

<html>
<head><title>Sample Page</title></head>
<body>
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
!@#$%^&*()-_=+/\|]}[{`~·♠
</body>
</html>

The output will be:

Click to enlarge

You see, it displays the texts as is. But note that the wildcard ♠ was displayed as ?, this is because this wild card was not recognized by the browser, in this case, I use Mozilla Firefox v.8.0.1 (latest version). However, if the browser supports the character, it will be displayed properly.

Now assuming we use the <p> element.

<html>
<head><title>Sample Page</title></head>
<body>
<p>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
!@#$%^&*()-_=+/\|]}[{`~·♠</p>
</body>
</html>

The result:

Click to enlarge

Well, it's still the same. In other words, by default, browsers treat texts inside the body as contents of <p>. The only problem with this is that you cannot align or break the texts into sentences. For example:

<html>
<head><title>Sample Page</title></head>
<body>
My name is Gabriel.
I am 3 yrs. old.
I live in Molo, Iloilo City
</body>
</html>

The result:


As you can see, even though I have broken the paragraph into separate sentences by vertically spacing them, the browser still treats it as one paragraph.

To remedy the problem, we have to use the <p> element.

<html>
<head><title>Sample Page</title></head>
<body>
<p>My name is Gabriel.</p>
<p>I am 3 yrs. old.</p>
<p>I live in Molo, Iloilo City</p>
</body>
</html>

Which will once again bring us into the output...



However, this time, note the difference... the paragraph has now been separated into double-spaced sentences. In some browsers, this may come out as single-spaced sentences.

Finally, you guys should know that by default, the texts (either or neither using the <p> element), will come out as black in color, with a varying size depending on the browser but is usually normal in size, and left aligned. In some browsers, it is also impossible to create single-spaced sentences without using a stylesheet or an attribute.

Well, that's all for now... next time, I am going to explain the <p> attributes, which would give you more paragraph styles, and likewise, more control of your paragraph. Until then...

Sunday, November 20, 2011

Basic HTML Tutorial: Background Colors

Welcome to the second installment of the Basic HTML tutorial guys and gals. Last time, I discussed some of the basics of HTML (see here), this time, I am going to continue the lesson from where I left off. Today's post will be covering background colors. Every website has one, usually, the default is white (if background color is not set), but if you want to assign new background colors to your site, then read on...

Background color can be assigned in the body of the page. It can also be inserted in div or divider elements, in texts, and in tables. But in this tutorial, since this is the basics, I am only going to cover the background color of the page.

Note that background color is an attribute rather than an element. An attribute is what gives an element its properties. We will go deeper into that on the advance lessons later on, but for now, let's know what is the attribute to use...

The attribute to use is bgcolor, it is displayed as bgcolor="x", where x=any color. Depending on a browser, it may be able to read high level languages such as "white", "blue", "red", "yellow", etc. However, I recommend using the hexadecimal color attribute which is triggered by a sharp (#); since this is the standard.

The hexadecimal color calling comes in 6 digits and starts with an # for example, #000000.

Now the digits are grouped by twos. ie. 00 00 00, each group corresponds to a color. See the diagram below:



The first two corresponds to red. The next two digits following the first group corresponds to the color green while the last two to blue. Also note that the values are in hexadecimal so it can range from 0-9 then a-f, where "0" is the lowest value and "f" is the highest. Hexadecimals by count appears like this when in order 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10...

Now, let's have a demonstration... assuming we want a page to have a red background...

to do this:

<html>
<head><title>red page</title></head>
<body bgcolor="#ff0000">
</body>
</html>

Here's the explanation, the body by default has a background color of white, however, using the bgcolor attribute, we can choose a different background color for the page, and since we pick #ff 00 00, we get a red page.

This is how it'll look like when opened in any browser.



Now, what if we pick #00 ff 00?

Well, it should come out like this:



Since we render red and blue to 0, both colors are no longer active, and by increasing the value of the digits corresponding to green to the highest, we end up with a bright green color.

Of course, aside from the 3 colors, you can make out other colors by combining the three. You can get purple, yellow, brown, etc. if you know how to mix them properly. In which case, you should refer to the color wheel.

Finally, aside from the hexadecimal value, you can also use the rgb value. It is written as bgcolor="rgb (0,0,0)", where the first digit corresponds to red, the second to green, and the third to blue, however, instead of displaying it in hexadecimal, we use whole numbers 0-255, where 0 is the lowest, and 255 is the highest value. 255 also corresponds to ff.

For example:

<html>
<head><title>red page</title></head>
<body bgcolor="rgb (255,255,0)">
</body>
</html>

The result:



It's yellow, because combining red and green yields yellow.

So that completes our tutorial, do some experimenting with the colors. Until next time...

Related

Basic HTML Tutorial

Thursday, November 10, 2011

Basic HTML Tutorial

OK, I'm going to make this quick and easy... but before anything else, let's define what is HTML? It would be ironic if you manage to learn it and yet doesn't even know what it is...

HTML or HyperText Markup Language is the predominant markup language for web pages. HTML is written in the form of HTML elements consisting of tags.

Every web browser is capable of reading HTML, once it is received by the web browser, it is then read and translated into a form visible or audible to the user. The browser does not display the HTML tags, but uses the tags to interpret the content of the page.

With that said, learning HTML would then enable you to create web pages. Now what is a web page? An example of it is the one you are reading right now, this is a web page.

Note that there are many programs and platforms that enables you to create web pages, there's Adobe Dreamweaver, MS Front Page, MS Word, etc. Yes, even MS Word can create pages although this one is not recommended as it does not seem to follow W3C's standard.

Now, what is W3C? W3C stands for World Wide Web Consortium, it is an international community that develops open standards to ensure long-term growth of the web. As you can see, there are lot of web browsers that are currently being used. There's Windows Internet Explorer, Mozilla Firefox, Opera, Google Chrome, Safari, etc. and each of these web browsers interpret HTML differently, and if your markup language doesn't follow standard writing, it may appear good on one web browser, but won't appear correctly on another. Thus, W3C maintains a standard that should be follow so to enable your language to work correctly on all browsers. As previously said, there are many programs and platforms that could generate a hypertext markup language for you automatically, but as for us... let's use the Notepad or Wordpad. You can find these programs under Accessories if you are using Windows OS. Anyway, just use any program that could save text as HTML.

Let's begin...

The HTML opens with the tag HTML Note that the tag should always be enclose within the < and > container. See below:

<HTML> or it can also appear in small letters <html>

Also note that when you open a tag, it also needs to be close. The closing tag begins with a slash. For example for <HTML>, the closing tag should be </HTML> or </html>. However, the closing tag for HTML should need to be always found at the very end of the page as other HTML tags should need to be contained within the HTML element.

HTML should always be the first and the last tag to appear. It marks the beginning and the termination of the HTML code.

The other tag to follow HTML is the <head>. The head has several elements contained therein. And since this is the basics, let's get acquainted with the <title>.

The <title> is the title of the page. The word or texts contained in between the open and closing title tag will appear as the title of the page. For example, <title>Phantom Maelstrom</title>, this will create a web page with the title Phantom Maelstrom.

After closing the title tag, proceed by closing the head tag with a </head>. The codes should appear like this:

<html>
<head>
<title>Phantom Maelstrom</title>
</head>

</html>

The result of this code would be...



You see? Now the page has a Phantom Maelstrom title when opened on a browser.

Now let's proceed to the body or the <body> tag.

The body tag contains the body of a page. This displays the contents. The body tag follows the closing head tag and ends before the closing html tag. It has many elements to employ, but let's start with the simplest of them all. The paragraph tag or <p> tag.

The <p> tag is contained within the body tags. The tag is use to display texts or a paragraph if it's comprising of sentences. The texts should be contained within the open p and closing p tag. For example, I want to display a text with the message "Hello World".

The code looks like...

<html>
<head>
<title>Phantom Maelstrom</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>

It would come out as...



So there you have it... The basics! Now go ahead and try it. Write these codes in a Notepad then save it as htm or html. For example phantommaelstrom.htm or phantommaelstrom.html, where phantommaelstrom is the file name, and htm and html is the extension name. This will tell your computer that these files should be opened in a web browser ie. Internet Explorer, Firefox, etc.

If you have questions, feel free to drop me a comment... next tutorial would be about how to color the background of the page. Stay tuned...

Related

Basic HTML Tutorial: Background Colors