Skip to content
  • iImagine
  • Register
  • Log In

Web Development School

Learning made easy.

  • Books
    • Beginning Web Development with ASP.Net Core & Client-Side Technologies
      • TOC
      • Part 1
        • Chapter 1: Static HTML – Designing the landing page
      • Part 2
        • Chapter 2: ASP.Net Core – Let’s talk Dynamic
        • Chapter 3: Introduction to ASP.Net Core MVC
          [ASP.Net Core v9]
      • Part 4
        • Chapter 7: Using Server Side & Client Side technologies together
          [ASP.Net Core v7 & Angular 15]
  • Environment Setup
    • Installing Angular
    • Installing Visual Studio 2022
    • Installing SQL Server 2022 Express
    • Installing Postman
    • Installing Git for Windows
  • Blog
  • iImagine WebSolutions
  • Events
  • Learning Videos
  • Toggle search form

Images and the HTML Image Element.

In the last module we laid out the html outlines for each category’s result set and defined the data we want to show for each vehicle result. Now, let’s fill in the vehicle data!

Below is a screen shot of what the webpage will look like at the end of this module.

You can also see a working version of what we will have built so far by the end of this module at the following link:

Fred’s Cars, Jeeps & Trucks

Table Of Contents
  1. Preparing for the Module
    • Extract the code
  2. Modify the code
    • The HTML Image Element
  3. Wrapping up the Fred's Cars landing page.
  4. What's Next

Preparing for the Module

The html code that generates the screenshot above uses images for the thumbnail preview in each vehicle result. You can download all the html code and the images it depends on in the screenshot above from the following link so your webpage can access the needed images and resources. Also if you want you can cut and paste the code from the downloadable fredscars.html file so you don’t have to type in the whole example. Or you can look at the downloaded code and compare to your own file and fix any errors.

Download Fred’s Cars webpage example

Extract the code

The folder you download from the link above is a compressed folder so you will need to decompress or extract the html file and images in order for the images to show up in the browser and for the JavaScript to work.

Windows comes with a utility to decompress files and folders. You can right click on the downloaded folder entitled “Chapter01Mod9.zip”, and click, “Extract All”.

Once you run the extract utility on the downloaded zip folder, you will have another folder next to it with the same name but without the “.zip” extension portion in the folder name. This is the folder you can run the webpage from.

You can either
* copy over the contents of your “C:\development\fredscars” directory with the contents of the downloaded folder
or
* make the modifications to fredscars.html yourself in the “Modify the Code” section below.

You can also use the contents of the downloaded html file to check for errors if you decide to type in the code below yourself in your current fredscars.html file. Just make sure your fredscars folder has the image folders and images in the same structure as the downloaded folder.

Modify the code

Modify the contents of fredscars.html with the following code, save your file, and refresh your browser:

<!-- ... -->
      .result-li-vin {
         margin-bottom: 10px;
      }
      .result-image {
         width: 65%;
	 padding: 15px;
	 display: block;
	 margin-left: auto;
  	 margin-right: auto;
      }
   </style>

   <!-- ... -->   

   <div id="cars" style="display: block;">
      <div class="row">
         <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2021</li>
	       <li><strong>Make:</strong> Dodge</li>
	       <li><strong>Model:</strong> Challenger</li>
	       <li><strong>Color:</strong> Frostbite</li>
	       <li class="bg-info"><strong>&nbsp;Price: $64,164</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 2C3CDZFJ8MH631199</li>
	    </ul>
	    <hr />
	    <img src="images/cars/car1.webp"
	         class="result-image" />
	 </div>
	 <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> Used</li>
	       <li><strong>Year:</strong> 2020</li>
	       <li><strong>Make:</strong> Ford</li>
	       <li><strong>Model:</strong> Escape</li>
	       <li><strong>Color:</strong> Oxford White</li>
	       <li class="bg-info"><strong>&nbsp;Price: $22,999</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 1FMCU0F63LUC25826</li>
	    </ul>
	    <hr />
	    <img src="images/cars/car2.webp"
	         class="result-image" />
	 </div>
	 <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2021</li>
               <li><strong>Make:</strong> Dodge</li>
	       <li><strong>Model:</strong> Durango</li>
               <li><strong>Color:</strong> Black</li>
	       <li class="bg-info"><strong>&nbsp;Price: $50,557</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 1C4RDJDG5MC837730</li>
	    </ul>
	    <hr />
	    <img src="images/cars/car3.webp"
	   	 class="result-image" />
	 </div>
      </div>
      
      <div class="row">
         <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2021</li>
	       <li><strong>Make:</strong> Nissan</li>
	       <li><strong>Model:</strong> Niro</li>
	       <li><strong>Color:</strong> Blue</li>
	       <li class="bg-info"><strong>&nbsp;Price: $24,690</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 2XYZT67JTF24AZG856</li>
	    </ul>
	    <hr />
	    <img src="images/cars/car4.png"
		 class="result-image" />
	 </div>
	 <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2021</li>
               <li><strong>Make:</strong> Kia</li>
               <li><strong>Model:</strong> Stinger</li>
	       <li><strong>Color:</strong> Gray</li>
	       <li class="bg-info"><strong>&nbsp;Price: $36,090</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 6FG146B89624AZ7952</li>
	    </ul>
	    <hr />
	    <img src="images/cars/car5.png"
	         class="result-image" />
	 </div>
	 <div class="col result-column">
            <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2021</li>
	       <li><strong>Make:</strong> Kia</li>
	       <li><strong>Model:</strong> Stinger</li>
	       <li><strong>Color:</strong> Gray</li>
	       <li class="bg-info"><strong>&nbsp;Price: $36,090</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 6FG146B89624AZ7952</li>
	    </ul>
	    <hr />
	    <img src="images/cars/car6.png"
	         class="result-image" />
         </div>
      </div>
   </div>

   <div id="trucks" style="display: block;">
      <div class="row">
         <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2022</li>
	       <li><strong>Make:</strong> Ram</li>
	       <li><strong>Model:</strong> Crew Cab</li>
	       <li><strong>Color:</strong> Black</li>
	       <li class="bg-info"><strong>&nbsp;Price: $68,400</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 3C6UR5DL8NG157035</li>
	    </ul>
	    <hr />
	    <img src="images/trucks/truck1.webp"
		 class="result-image" />
	 </div>
	 <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> Used</li>
	       <li><strong>Year:</strong> 2017</li>
	       <li><strong>Make:</strong> Ram</li>
	       <li><strong>Model:</strong> Crew Cab</li>
	       <li><strong>Color:</strong> Red</li>
	       <li class="bg-info"><strong>&nbsp;Price: $33,000</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 1C6RR7PT0HS814596</li>
	    </ul>
	    <hr />
	    <img src="images/trucks/truck2.webp"
		 class="result-image" />
	 </div>
	 <div class="col result-column-empty">
	    <!-- empty col -->
	 </div>
      </div>
   </div>

   <div id="jeeps" style="display: block;">
      <div class="row">
         <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
               <li><strong>Year:</strong> 2022</li>
	       <li><strong>Make:</strong> Jeep</li>
	       <li><strong>Model:</strong> Compass</li>
	       <li><strong>Color:</strong> White</li>
	       <li class="bg-info"><strong>&nbsp;Price: $34,980</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 3C4NJDFB5NT114024</li>
	    </ul>
	    <hr />
	    <img src="images/jeeps/jeep1.webp"
		 class="result-image" />
	 </div>
	 <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2022</li>
	       <li><strong>Make:</strong> Jeep</li>
	       <li><strong>Model:</strong> Compass</li>
	       <li><strong>Color:</strong> Red</li>
	       <li class="bg-info"><strong>&nbsp;Price: $39,275</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 3C4NJDCB1NT118172</li>
	    </ul>
	    <hr />
	    <img src="images/jeeps/jeep2.webp"
		 class="result-image" />
	 </div>
	 <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
	       <li><strong>Year:</strong> 2021</li>
	       <li><strong>Make:</strong> Jeep</li>
	       <li><strong>Model:</strong> Grand Cherokee</li>
	      <li><strong>Color:</strong> Pearlcoat</li>
	       <li class="bg-info"><strong>&nbsp;Price: $53,575</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 1C4RJKBG5M8201121</li>
	    </ul>
	    <hr />
	    <img src="images/jeeps/jeep3.webp"
		 class="result-image" />
	 </div>
      </div>
      <hr />
      <div class="row">
         <div class="col result-column">
	    <ul class="list-unstyled" style="text-align:left;">
	       <li><strong>Status:</strong> New</li>
               <li><strong>Year:</strong> 2021</li>
	       <li><strong>Make:</strong> Jeep</li>
               <li><strong>Model:</strong> Wrangler Sport S</li>
	       <li><strong>Color:</strong> Green</li>
	       <li class="bg-info"><strong>&nbsp;Price: $40,940</strong></li>
	       <li class="result-li-vin"><strong>VIN:</strong> 1C4GJXAN0MW856433</li>
	    </ul>
	    <hr />
	    <img src="images/jeeps/jeep4.webp"
	         class="result-image" />
	 </div>
	 <div class="col result-column-empty">
	    <!-- empty col -->
	 </div>
	 <div class="col result-column-empty">
	    <!-- empty col -->
	 </div>
      </div>
   </div>
<!-- ... -->

Let’s examine the code modifications above.

The HTML Image Element

Each result for a vehicle now has an <img> element with a src attribute and a class attribute. The image element in html is as its name suggests, used to display images in the browser.

<img src="images/cars/car1.webp"
     class="result-image" />

In the code snippet above, the image tag has a src attribute giving the path to the image that should be shown. This src attribute is using a relative path. A relative path starts from the html code file and looks for the image from there. Here the path it will look for the image, starting from fredscars.html, is the images folder on the same folder level as fredscars.html, and from there goes to the cars folder, and inside the cars folder uses the image named car1.webp.

If we wanted to use an absolute pathway the src attribute value might look like this:
c:\development\fredscars\images\cars\car1.webp.

The problem with an absolute path compared to a relative path is if you move your development folder, fredscars, to another computer, server or to a different place in your folder or directory structure on your development machine, the link to the image could break. Relative paths start from the code file itself so as you move your development folder around, for instance in deployment, the links will not break.


The image elements in each result are also using a new css class called “result-image”:

.result-image {
   width: 65%;
   padding: 15px;
   display: block;
   margin-left: auto;
   margin-right: auto;
}

The width property above is setting the width of the image to 65% of the space the image element would normally take up in its parent element, in this case the div column holding all of the vehicle result data. The margin-left and margin-right properties are set to auto in order to center the image.


We have also added another new css class called “result-li-vin” and we are applying the new class to each vehicle’s vin list item:

.result-li-vin {
   margin-bottom: 10px;
}

This pushes the image down 10 pixels to give some white space from the <hr> element above it.


And finally, we added the bootstrap “bg-info” css class to each vehicle’s price list item to give that data point a bootstrap lighter blue background then bg-primary would give, for example on the category buttons.

Wrapping up the Fred’s Cars landing page.

At this point you should have a working webpage with the html structure laying out the positioning of your content, JavaScript functionality allowing your users to look at different categories of vehicle, and static data showing information about each vehicle along with thumbnail images to give the user an idea of what each vehicle looks like.

Static data here refers to the fact that we laid out each vehicle result by hand and coded the html. In later chapters we’ll see how to store this data in a database and dynamically build html pages rendering the data and images from the database.

What’s Next

In the next module we will briefly return to the topic of reusability and build a details page for one of the vehicles.

< Prev
Next >

Leave a ReplyCancel reply

Chapter 1: Static HTML – Designing the landing page.

  • Static HTML – Designing the landing page.
  • Let’s get started!
  • Mock your site with HTML
  • Make CSS easy with Bootstrap
  • Mock your content
  • Introducing JavaScript
  • JavaScript Code Improvements
  • Results Data
  • Images and the HTML Image Element.
  • Revisiting Reusability for CSS and JavaScript
  • Reuse for HTML: PART 1
  • Reuse for HTML: PART 2
  • Details Page – Using a Bootstrap Component
  • Creating Links
  • Chapter One Conclusion

Chapter 2: ASP.Net Core – Let’s talk Dynamic

  • Introduction to ASP.Net Core
  • What is .Net?
  • What is ASP.Net
  • Introduction to Entity Framework Core

Chapter 3: ASP.Net MVC Core – Models, Views, and Controllers [ASP.Net Core v9]

  • Introduction to ASP.Net Core MVC
  • Create the project: ASP.Net Core MVC
  • Explore the ASP.Net Core Empty Web Project Template
  • Configure the Application for MVC
  • Create a Controller: Home Controller
  • Create a View: Index View for the Home Controller
  • Install Bootstrap using Libman
  • Create the Layout template
  • Create the Model
  • Install EF Core & Create the Database
  • Seed the Database: Loading test data
  • DI (Dependency Injection): Display a List of Vehicles
  • Repository Pattern: The Vehicles Repo
  • Unit Test 1: Home Controller Can Use Vehicle Repository
  • Unit Test 2: Vehicle Repository Can Return List
  • Add the ImagePath Migration and Thumbnail images to results
  • Pagination: Create a Custom Tag Helper
  • Sorting
  • Category Filter
  • Partial View: Break out the vehicle results
  • View Component: Create dynamic category buttons
  • Create the Details page
  • Create the Create Page
  • Create the Update Page

Chapter 7: Using Server Side & Client Side technologies together. [ASP.Net Core v7 & Angular v15]

  • Intro to Full Stack Development
  • Fred’s Cars – Full Stack Development
  • Prepare the environment
  • Create the Visual Studio Solution
  • Add the ASP.Net Core Web API project
  • Add the Angular Project
  • Wire it up!
  • WeatherForecast: Understanding the basics
  • Vehicles API Controller: Mock Data
  • Vehicles Angular Component: Consuming Data
  • Routing and Navigation
  • Using a Component Library: Angular Material
  • Our first Angular Material Component: MatToolbar
  • Configuring for Saas: CSS with superpowers
  • Create the Header & Footer components
  • Displaying Results with MatTable
  • Loading: Using a Progress Spinner
  • MatTable: Client-Side Paging and Sorting
  • MatSidenav: Create a Search Sidebar
  • MatCheckbox: Category Search UI
  • Adding an image to the welcome page
  • Create the database with Entity Framework Core migrations
  • MatPaginator & PageEvent: Custom Server-Side Paging
  • Unit Testing: Custom Server-Side Paging
  • Repository Pattern: VehicleRepository
  • Unit Test: Paging in the Vehicles controller
  • Server-Side Sorting
  • Unit Tests: Sorting
  • Filter (Quick Search)
  • Unit Tests: Filter feature
  • Advanced Search: Categories
  • Unit Tests: Search by category
  • Progress Spinner: Final Fix

TOC

  • What were WebForms?
  • Enter MVC
    • Understanding MVC
    • Advantages of MVC
  • ASP.Net Core MVC – A total rewrite
  • ASP.Net Core 2 MVC – Here come Razor Pages
    • Understanding Razor Pages
  • ASP.Net Core 3 – Dropping the MVC reference
    • Understanding Blazor
  • Dropping the MVC reference
  • Hello .Net 5!
  • What’s Next? – Here comes .Net 6.

Recent Posts

  • Angular Commands Cheat Sheet
  • Installing Git for Windows
  • Installing Postman
  • Installing SQL Server 2022 Express
  • Installing Visual Studio 2022

Recent Comments

No comments to show.

Archives

  • November 2023
  • October 2023
  • June 2023
  • October 2021

Categories

  • Angular
  • ASP.Net
  • Environment Setup
  • See All
  • SQL Server
  • Visual Studio
  • Web API & Rest Services

WordPress Theme Editor

Copyright © 2025 Web Development School.

Powered by PressBook Blog WordPress theme