Skip to main content

HTML BASICS : CLASS 104

Hello and welcome back.
This is the 4th lesson in a series of HTML for beginners tutorials.
In this tutorial, we shall discuss how to add images in your website.
At this point, your my_site.html file should have the following code in it.

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h2>NASA | JPL</h2>
    <h1>ON A MISSION</h1>
    <h4>PODCAST</h4>

    <p>A new podcast from NASA</p>

    <ul>
        <li>Arrival</li>
        <li>We Are the World</li>
        <li>Worlds of Wonder</li>
    </ul>

     <ol>
        <li>NASA is cool</li>
        <li>Coding comes second, arguably.</li>
        <li>What is third place?!</li>
    </ol>

    <table>
    <tr>    <th >Name</th>          <th >Title</th>         </tr>
    <tr>    <td >John Doe</td>    <td >Tutor</td>       </tr>
    <tr>    <td >Jane Doe</td>    <td >Student</td>    </tr>
    </table>

   
</body>
</html>

Let's get started.

You first need to know what an 'attribute' is.
In a programming context (environment), an attribute refers to 'a certain property of a certain object' . An attribute has a name and a value.
To clarify, consider the statement 'a black box'.
Here the object 'box' has the attribute named 'color' whose value is 'black'.
Similarly, the statement 'a tall man' speaks of  an object 'man' whose attribute 'height' has the value 'tall'.
'The oval office' speaks of the object 'office' whose attribute 'shape' has the value 'oval'.
'A 10 dollar tshirt'  speaks of the object 'tshirt' whose attribute 'price' has the value '10 dollar'.

Got it? .... Great!


To add an image in html, we shall use the tag '<img> .
Unlike other html tags we have learned so far, the image tag (<img>), has no closing tag.
The image tag has an attribute named source.
The value of the source attribute of an image is the image's location.
The source attribute in html is written in short form as 'src'.

Let's add an image to our site and see how this all works in practice.
  1. Click here to get an image. When the image opens, right click on it and click 'Save Image As...' . From the window that opens up, go to the location where you have saved your my_site.html file. Under file name, type 'apollo' then click 'Save'.
  2. Open my_site.html in Sublime text (or whichever text editor you decided to use),  and type the following code below the closing table tag (</table>).
  3.          <img src="apollo.jpg">
  4. Save the file and open it up in your browser. The image shall now be displayed below the second table in your site. 
  5.  
The code <img src="apollo.jpg">  says this, "there is an image located in the same folder as this my_site.html file, named apollo of type/extension jpg. get that image and display it".

Now, do the following:
  1. Go to where you have saved the file my_site.html. Create a new folder and call it 'images'.
  2. Move (cut & paste) the apollo image to the images folder. 
  3. Open my_site.html in your browser. Notice that the image is no longer displayed. This is because the image's location has been changed.
  4. In Sublime text, change the code <img src="apollo.jpg"> to:
  5.         <img src="images/apollo.jpg">
  6. Save the file and open it up in your browser (or refresh your browser if it is already open). The image now appears again.
The code <img src="images/apollo.jpg">  says this, "there is a folder called images located in the same folder as this my_site.html file. Inside it, there is an image named apollo of type/extension jpg. get that image and display it".


You can use this video to follow up, if the text details above are confusing, but hopefully you got it.
And you can leave any question/comment in the comment section below. 
That is all for today, happy coding.







Comments

Popular posts from this blog

CSS BASICS : CLASS 106

Hello and welcome back to this tutorial series for beginners in web development. This tutorial assumes you grasped all concepts discussed in the previous 5 html classes. You can test yourself using the exercise given here . At this point, your my_site.html file should have the following code in it.  <!DOCTYPE html> <html> <head>     <title></title> </head> <body>     <h2>NASA | JPL</h2>     <h1>ON A MISSION</h1>     <h4>PODCAST</h4>     <p>A new podcast from NASA</p>     <ul>         <li>Arrival</li>         <li>We Are the World</li>         <li>Worlds of Wonder</li>     </ul>      <ol>  ...

HTML BASICS : CLASS 109 part II

Hello and welcome back. In part I , we learned the theory behind the html div ta g and the form elements . We have quiet some coding to do in this part, so let's get to it. Create a new html file and name it sections.html . Open the file in your text editor (e.g. Sublime Text), type in the following code and save it. You can go ahead and view it on your browser afterwards, though it won't look quiet good just yet. <!DOCTYPE html> <html> <head>     <title></title>     <link rel="stylesheet" type="text/css" href="sections.css"> </head> <body>     <div id="header">         <h2>My Site</h2>     </div>     <div id="content">         <div id="main">             <p>Welcome to my website.<br>Please give me your feed...

HTML BASICS : CLASS 102

Hello and welcome back. This is the second class in a series of tutorials for beginners in web development. You can access the first one here. By this point you should have a file named my_site.html with the following code in it: <!DOCTYPE html> <html> <head>     <title></title> </head> <body>     <h4>NASA | JPL</h4>     <h1>ON A MISSION</h1>     <h2>PODCAST</h2> </body> </html> Great! It is a bit weird having a couple of headings with no further details, isn't it? Let us add some more text that explains what this whole 'NASA ON A MISSION PODCAST' stuff is about. For this we will use a different tag, the paragraph tag which opens with ' <p> ' and closes with a ' </p> ' .  After the bottom heading, type the following :  <p>A new podcast from NASA</p> Cli...