Advertise here.
Showing posts with label HTML tutorials.. Show all posts
Showing posts with label HTML tutorials.. Show all posts

Wednesday, 15 August 2012

HTML lesson #6 - Other useful stuff


In this lesson we'll learn about a few useful extra things to do in HTML.

Background sound

If you want a sound to play when your page is viewed then you need to use the <bgsound> tag. You also have to say how many times the sound must play with the loop attribute:
<bgsound src="mysound.mp3" loop="3">
You can use a few different types of sound files like MP3 and WAV. If you want the sound to loop forever just set loop="infinite".

Horizontal rules

You can put a horizontal line across your page by using the <hr> tag. You can change its color with the color attribute and you can change its thickness with the size attribute:
<hr color="red" size="5">
You are also able to change its width and height:
<hr width="300" height="100">
You can use pixels or % for width and height.

Special characters

If you put 3 spaces between the letter a and b in your html file you'll see that you still only get one space. If you want to put in more than one space you have to use a special character which is &nbsp;. To put 3 spaces between the letters a and b you would do the following:
a &nbsp;&nbsp;&nbsp; b
If you wanted to show an example of a tag on your page you would be able to use < and > because they would be seen as an html tag. You have to use &lt; for < and &gt; for >. The following example will give you the opening and closing BODY tags:
&lt;body&gt;
&lt;/body&gt;



There are a lot of other special characters but those are the most commonly used.

Attributes : Ankit Fadia, Mohammed E. Katz, Wadria William. learnprogramming.co.za

HTML lesson #5 - Frames


In this lesson we will learn about frames. Frames are a useful way to make websites download quicker because they divide a page up into sections and frames also make a website easier to maintain.

Your first frames page

When we want to use frames we don't use the <body> tags for the beginning and end of the content of our page, we use the <frameset> tags. We use the <frame> tag to create a frame. You need to start off by creating a new file called index.html. Now type and save the following in the file you've just created:
<head>
<title>My frames page</title>
</head>

<frameset cols="100,*">
   <frame src="menu.html">
   <frame src="home.html">
</frameset>
 
Now you need to create 2 files called menu.html and home.html. Put the opening and closing body tags in them but make menu.html have a red background and home.html must have a blue background. Here's what it should look like:
menu.html
<body bgcolor="red">
</body>
 
home.html
<body bgcolor="blue">
</body>
 
Make sure you save all of them in the same folder then open index.html in your web browser. You should see a 100 pixel wide, red section on the left hand side of the screen and a blue section on the right hand side of your screen. As you can see the frame document has put menu.html in a 100 pixel wide frame and it has put home.html in the frame on the left. If you look at the code for the frame page you'll see cols="100,*" in the <frameset> tag. This makes 2 columns with the first one 100 pixels wide and the second column as wide as the rest of the page. You can have more columns by adding in more lengths to the cols attribute so if you want 3 columns then it would be cols="100,100,*".
If we want menu.html at the top and home.html at the bottom of the page then we use rows instead of cols:
<frameset rows="100,*">
   <frame src="menu.html">
   <frame src="home.html">
</frameset>
 
This time you should see a 100 pixel high red section at the top and a blue section at the bottom of the page.

Rows and cols together

If we want to put 2 rows into a page with 2 sections in the bottom page we have to use another <frameset> tag inside the first one. We will also have to create another file called heading.html which will have a green background:
<frameset rows="100,*">
   <frame src="heading.html">
   <frameset cols="150,*">
      <frame src="menu.html">
      <frame src="home.html">
   </frameset>
</frameset>
 
heading.html
<body bgcolor="green">
</body>
 
You should now see a 100 pixel high green section at the top of the page and a 150 pixel wide red section on the left side underneath the green section and a blue section underneath the green section as well to the right of the red section.

Making a menu

You will have to create another file with a yellow background color called page2.html for this exercise:
page2.html
<body bgcolor="yellow">
</body>
 
We must now give the frame that has home.html in it a name:
<frameset rows="100,*">
   <frame src="heading.html">
   <frameset cols="150,*">
      <frame src="menu.html">
      <frame src="home.html" name="mainframe">
   </frameset>
</frameset>
 
At the same time we must create 2 links in menu.html:
menu.html
<body bgcolor="red">
<a href="home.html" target="mainframe">HOME</A><br>
<a href="page2.html" target="mainframe">PAGE2</A>
</body>
 
The target attribute in the A tag makes it display the page in the window called mainframe. If you click on PAGE2 then it will display page2.html in mainframe and if you click on HOME then it will display home.html in mainframe.

Other useful frame attributes

You will have noticed the grey border around each frame by now. We can make the border wider or get rid of it with the border attribute. If we want the border wider we can set it to something like 9 or if we want it to not be there then we set it to 0 like in the following example:
<frameset cols="100,*" border="0">
<frame src="menu.html">
<frame src="home.html">
</frameset>
 
We can also change the border color and if the borders can be resized:
<frameset cols="100,*" bordercolor="black" noresize>
<frame src="menu.html">
<frame src="home.html">
</frameset>
 
When you have a lot of text in a frame a scrollbar will appear but if you don't want the scrollbar to appear you can turn it off for that frame with the scrollbar attribute:
<frameset cols="100,*">
<frame src="menu.html">
<frame src="home.html" scrolling="no">
</frameset>
 
You may also want to change the space between frames. For this we use the framespacing attribute:
<frameset cols="100,*" framespacing="50">
<frame src="menu.html">
<frame src="home.html">
</frameset>

Sunday, 12 August 2012

HTML lesson #4 - Tables


In this lesson we are going to learn about tables. Tables are one of the most important things in web site building. Just about all websites use tables but you don't see them very often because they're hidden. Tables are used to format the text and images.

Your first table

To create a table you need to use the <table> tag. Here is what it look like:
<table>
</table>

As you can see they're just like normal tags but you have not got a table yet. You need to make table rows that contain table cells which hold your data. The <tr> tag is for a row and the <td> tag is for a table data cell. Here is a row with 3 cells in it:
123

<table border="1">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>

It is important to put something in a td otherwise it won't show up. Also note that I said border=1. If you want the table border to show up in some browsers you have to do this. You can change the 1 to something higher if you want a thicker border. In the following example we're going to create 2 rows each with 2 cells:
12
12

<table border="1">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>

Width and height

If you want to change the width or height of the cells then you use the width and height attributes. Theses can be used for the table or the tr or the td. Here's an example of making the table 100 pixels high and making each of the top cells 100 pixels wide:
12
12

<table border="1" height="100">
<tr>
<td width="100">1</td>
<td width="100">2</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>

Look at how the cells in the second row are the same width as the ones above them but don't have the width=100 attribute. Widths and heights are not only measured in pixels but can also be set in %. By simply putting a % after the 100 we make the table 100% of the width of the page.

Colspan and Rowspan

What if we wanted 1 cell in the top row and 2 cells directly underneath that cell? If you just make 1 cell in the top row and 2 in the bottom row it doesn't work. You need to use colspan:
1
12

<table border="1">
<tr>
<td colspan="2">1</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>

As you can see the top row spans 2 columns. You can do the same with rows like this:
12
1
<table border="1">
<tr>
<td rowspan="2">1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
</tr>
</table>

We just made the first cell span across 2 rows.

Text alignment

By default text in a table will be on the left side of the cell in the middle. Sometimes you'll want to position the text in the center of the cell or make at the top. We us the align attribute for horizontal text alignment and the valign attribute for vertical alignment. Here are examples of what you can get:
leftcenterrighttopmiddlebottom

<table border="1" height="100">
<tr>
<td width="100" align="left">left</td>
<td width="100" align="center">center</td>
<td width="100" align="right">right</td>
<td width="100" valign="top">top</td>
<td width="100" valign="middle">middle</td>
<td width="100" valign="bottom">bottom</td>
</tr>
</table>

Cellpadding and cellspacing

In each cell you'll notice that the text is not right up against the border of the cell. The space between the text and the border is called padding and we can increase or decrease it with the cellpadding attribute:
1

<table border="1" cellpadding="0">
<tr>
<td>1</td>
</tr>
</table>

1

<table border="1" cellpadding="9">
<tr>
<td>1</td>
</tr>
</table>

You can also increase or decrease the space between cells with the cellspacing attribute:
12

<table border="1" cellspacing="0">
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>

12

<table border="1" cellspacing="9">
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>

Colors

You can change the border color of a table or cell with the bordercolor attribute:
1

<table border="1" bordercolor="red">
<tr>
<td>1</td>
</tr>
</table>

You can also change the background color of a table or a cell:
1

<table border="1" bgcolor="red">
<tr>
<td>1</td>
</tr>
</table>

HTML lesson #3 - Images and links


In this lesson we will learn about:

-Putting images on your page

-Links

-Viewing other people's source code

Putting images on your page

To put an image on your page you must use the <IMG> tag. Notice that I say tag and not tags.
<img src="smile.jpg">


The result will be:

You can use the ALT property for when a picture doesn't show up:
<img src="nothing.jpg" alt="Picture not available">

Result:

Picture not available

Notice the yellow popup that appears after holding your mouse over it for a while. This popup will also appear if the picture is there. If you don't see the popup don't worry, some browsers don't respond that fast. Also if the above picture were to for some reason not fully load on your browser it should show "Picture not available".
What is important is that you know what the <alt> tags are for and how to use them.

Links

To put a link on your page you must use the <a> tags:
<a href="http://www.html.com">click here</a>
And this is what you'll get:
This is how you make a linking image:
<a href="http://www.html.com"><img src="lrnhtml2.jpg"></a>
And you'll get:


Something you may have noticed is the blue border around the image. To get rid of the border you must do the following:
<a href="http://www.html.com"><img src="lrnhtml1.jpg" border="0"></a>






Viewing other people's source code

Not recommended but some people learn better this way so If you would like to take a look at the code of a website, all you have to do is click on the "View" menu and choose "Source" while viewing the website. You can try it right now in your web browser, to view this page's source code. It's a bit more complex compared to what you've learnt so far, so don't scratch your head, if you don't understand anything. Bottom line is, you can always copy and paste source code (depending on how its licensed) if you like but it's better if you do your own coding so that you are actually learning something.

Friday, 3 August 2012

Html lesson #2 - Font Styles


In this lesson we will be learning about:
Changing text color and size.
Underlining, Bold and Italics.

Changing text color and size

For colorful text we need to use the <font> tag. You must type the words that you want the color to be applied to between the tags like this:
<font>Hello</font>
Now we must give the <font> tag the color property:
<font color="red">Hello</font>
You now see a red Hello in your web browser. You can also use hex value colors:
<font color="#FF0000">Hello</font>
The first 2 digits are for red, the next 2 are for green and the next 2 are for blue. I use this picture to remember it in my head:
|R|G|B|
If we want different size text then we still use the <font> tag but we use the size property. Example:
<font size="5">Hello</font>
SIZE has a range of 1-7. 1 being small and 7 being large. Let's see if you can do this:
Hello

Underlining, Bold and Italics

The <u> tags will underline the text between them:
<u>underlined</u>
Result:
underlined
The <b> tags will make the text between them bold:
<b>bold</b>
Result:
bold
The <i> tags will make text between italic:
<i>italics</i>
Result:
italics

Tuesday, 31 July 2012

First lesson in Html. Creating your first webpage...


I'm not going to waste your time teaching you about the history of html and the current versions, all that can be found in almost every encyclopaedic article about the subject. I'll just go straight to what you need to know, and how to use html to create web pages.

First of all, before we begin, you're going to need a text editor such as Notepad which we will be using to type our html code.

Open up that text editor and minimise it, just keep it open, on stand by, till you need to practise typing the code yourself.

Let's begin..

HTML is a really simple language to learn, what you need to understand first of all is that at the heart of html and in all html pages we use "things" called "tags" ; characterised by being enclosed in these signs "<html_tag>"; Let me elaborate, for example:

<font>

The above example is an opening tag and the following one is a closing tag:

</font>


These tags give properties to what you put between them.

Every HTML document must have the HTML tags to define it as a HTML document.

<html>

</html>

Go ahead and type those 2 tags.


Now we need some <head> tags. The <head> tags contain things like the document title. In between the <html> tags I want you to put your <head> tags and in between that you must put the <title> tags so that your entire document looks like this:

<html>
<head>
<title>My Page</title>
</head>
</html>


Now we must save the file. Make sure you save the file with the name index.html and also make sure that you change the save as type to All Files to make sure that it gets saved as a .html file and not a .txt file. Now open your new .html file in your web browser. Make sure you keep this window open. You need to save each time you have changed your document otherwise the changes won't appear in your web browser. You must also click the refresh button each time to see the changes.

Go back to your text editor and add the <body> tags:

<html>
<head>
<title>My Page</title>
</head>
<body>
</body>
</html>


You'll notice that the <head> tags go on top of the <body> tags just like a person's head goes on top of their body. The body is the main part of the document and is where most of the code goes.

Now we can learn about giving tags properties. You get your normal tags <body> and then you get properties in them like this:

<html>
<head>
<title>My Page</title>
</head>
<body bgcolor="red">
</body>
</html>


bgcolor="red" is the background color of the page. In this case it will have a red background. You must always put properties between inverted commas.

Go back to your web browser after you have saved and click the refresh button. You now have a red background. We can also add in text:
<html>
<head>
<title>My Page</title>
</head>
<body bgcolor="red">
Hello
</body>
</html>


This time when you go back to your web browser you will see a red background with the word Hello written in black. We can change the text color like this:

<html>
<head>
<title>My Page</title>
</head>
<body bgcolor="red" text="white">
Hello
</body>
</html>


One important thing that you need to know is that pressing ENTER and going to the next line in notepad will not go to the next line in the web browser. You must use the <br> tag. Notice how I say tag and not tags. <br> is one of the only tags that can go by itself. If you want to skip a line then use the <p> tag. Try this:

<html>
<head>
<title>My Page</title>
</head>
<body bgcolor="red" text="white">
Hello<p>
How are<br>

You
</body>
</html>


You will see that even though "How are" is on the same line as "you" it still goes to the next line in your web browser because of the <br>

Try leaving lots of spaces between 2 words like this:

<html>
<head>
<title>My Page</title>
</head>
<body bgcolor="red" text="white">
Hello     There
</body>
</html>


Now look at it in your web browser. It still shows up with one space between the 2 words. Web browsers don't allow you to leave spaces open like that. You have to use the special space character.

<html>
<head>
<title>My Page</title>
</head>
<body bgcolor="red" text="white">
Hello&nbsp;&nbsp;&nbsp;There
</body>
</html>


Each &nbsp; is a space so in the above example we would have 3 spaces between "Hello" and "There". Which brings me to skipping multiple lines. You can't just type in <br><br><br> to skip a few lines. You have to put &nbsp; between them like in the next example:

<html>
<head>
<title>My Page</title>
</head>
<body bgcolor="red" text="white">
Hello
<br>&nbsp;<br>&nbsp;<br>
There
</body>
</html>


<p> works in the same way.

That's it for our first lesson, go practice what you've learnt until you've mastered those tags.

Go to the next lesson #2 to continue learning. 

Either click the blogger link below saying "newer post" or navigate to the blog archive on the right and find it, alternatively you can search for it at the top of this or any page on the sidebar using the search box we placed there or use the page menu to locate html tutorial lessons; using blogger tags.