IT581: Practicum in Web Development, Summer 2015 (Hybrid)

Lesson 5: Inserting images in pages

Now that we can construct web pages with hyperlinks, and style them attractively, we'll see how to add some useful extra elements.


Images


Image formats


The img element


The src attribute


The alt attribute


Example

The tag:

    <img src="http://wyrd.hood.edu/~dong/it581/s2015/graphics/lesson05/sunset.jpg" 
           alt="Sunset" />

The result:
Sunset


Image dimensions in style rules


Example

        <style type="text/css">
                img {
                   width:100px;
                   height:200px; 
                   }
                #wide_pic {
                   width:450px;
	                  height:75px; 
                   }
                img.small_pic {
                   width:15px;
                   height:20px; 
                   }
         </style>

Inline style rules

 


Inline image dimensions

<img src="http://wyrd.hood.edu/~dong/it581/s2015/graphics/lesson05/sunset.jpg"
          alt="Sunset"
          style="width:200px; height: 50px;" />
          
<img src="http://wyrd.hood.edu/~dong/it581/s2015/graphics/lesson05/sunset.jpg"
          alt="Sunset "
          style="width:100px; height: 100px;" />
          

Sunset Sunset

Note: To see the true dimensions of an image, right-click on the image and then choose "Properties" from the popup menu.

 


Effects of displaying an image smaller/greater than the original

 


Images and links

 


Example

<a href="http://www.hood.edu/">
    <img src="http://wyrd.hood.edu/~dong/it581/s2015/graphics/lesson05/hood.jpg "
         alt="Hood College" ></a>

Hood College

 

How images are displayed

 


Example - inline image

<p style="text-align: center">... image tag here ...</p>

... x ...

 


Example 5.1 - inline images

 


The float property

 


Example 5.2 - floated images

 


Borders

 


Example

<style type="text/css">  
   img { border-style: double;  
         border-width: 20px;          
         border-color: teal; }  
</style>

the border will look like:

x

Variation

The three parts can be combined one border property rule. The individual values are separated by spaces.

        <style type="text/css">
            img { border: double 20px teal; }
        </style>

Example 5.3 - borders

You can add a border style to paragraphs and other elements too.

<style type="text/css">  
        body {margin: 20px;
              background-color: #FFFF00;
              border: dotted 30px red;}
        h1 {border: ridge 8px  #00FFFF}
        h2 {border: double thick silver}
        strong { border: solid medium #00FFFF; }
        p { margin: 25px; }
</style>

Complete example page


Example 5.4 - Floating Other elements

 

      <style type="text/css">    
         body {background-color: white; color: black}
         img {float: right }
         p.first { 
               width: 250px; 
               float:left; 
               border: solid thin red;}
      </style>

Complete example page


Examples

Here's a real site with a larger image, showing the wrapping technique used in a page. margins keep the text from bumping up against the image.


Guidelines

Comments to: dong@hood.edu
Last Modified: 08 July 2015. 13:20