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

HTML BASICS : CLASS 103

Hello and welcome to the third in a series of beginner level classes for web developers. In the previous lesson (see here ), we learned about the paragraph and list tags. At this point the code in your my_site.html file should look like this: <!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...

CSS BASICS : CLASS 107

Hello and welcome back to this series of tutorials for beginners in web development. So far we have a simple html page and a css file linked to it. We begin this tutorial by creating new html and css files, in the same folder as where my_site.html is located. We shall call them index.html and index.css respectively. Done? Great! Link the two files together , by opening up index.html in your text editor (e.g. Sublime Text) and typing the following code below the closing title tag  </title>  and before the closing head tag </head> :               <link rel="stylesheet" type="text/css" href="index.css"> Inside the body of your html (i.e after <body> and before </body>),  type the following html code :              <p> This is a paragraph </p>          ...

CSS BASICS : CLASS 109 part III

Hello and welcome back to this tutorial series  for beginners in web development with HTML & CSS. We have been discussing form and div elements in the previous sections of this class (see class 109 part I and II ). You should have 2 files, one sections.html file and another sections.css file linked to it. Next, we will discuss the css code we used in the sections.css, particularly 2 new attributes ' display ' and ' float ' .  This is the CSS code that we used to style our sections.html page. #header{     background-color: grey;     padding-top: 5px;     padding-bottom: 5px;     padding-left: 15px; } h2{     margin: 0px;     color: white; } #content{     padding-left: 15px; } p{     display: inline-block;     float: left;     margin-right: 50px; } form{     display: inline-block;     border...