Module 4-Website Images (Chapter 4)
Module 4-Website Images (Chapter 4)
Website Images
EMBEDDED AND BACKGROUND IMAGES, BORDERS, SHADOWS
2
Adding Images This Week!
Then this slideshow covers a host of other cool effects, like borders,
border radii, box shadows and more.
Last, but not least, we will come back to the CSS Background Images.
HTML Embedded Images
First: HTML Embedded Images
Use HTML images when they are key to the website content
For the height and width, you don't add "px" behind
the number.
You can see it in practice in the code below.
<img src="images/eclipse.jpg" alt="sliver of sun during
eclipse" height="100" width="100">
The src Attribute
One of the attributes for an image is the src
for "source". The src attribute tells the
browser where to find the images.
https://webdevstudents.com/website-files-and-folders-
explaining-the-magic/
<img> is a Self-Closing Tag
<h1>
<br>
<img>
<p>
<!DOCTYPE html>
<hr>
Pop Quiz
<h1>
<br>
<img>
<p>
<!DOCTYPE html>
<hr>
Finding Images on Google
For practice, we can use absolute links in JSFiddle. An absolute link is a full link, with the https
and the domain name, like this:
https://webdevstudents.com/wp-content/uploads/2020/12/toolbox-300x300.jpg
1. Go to images.google.com
2. Click on Tools
3. Use an icon size image for the next exercise. Tools->Size->Icon
Demo: Embedded Images 4.1
2. Go to Google Images, get a icon-sized image. Find the image you like
and open the image in a new window to grab the URL. Or you can use
this image:
https://webdevstudents.com/wp-content/uploads/2020/12/toolbox-300x300.jpg
3. Add an <img> to your JSFiddle, and put in the src, height, width, and
alt attributes. Use the full url of the image. If you use the image
above, the size is 300 width and 300 height.
19
Your JSFiddle Should Look Like This…
Not sure what to do? Check your code against the code below.
Keep the Chrome tab open to your JSFiddle. We will keep adding to it throughout the presentation. If the image you
picked out on Google Images didn't work out, switch over to the ToolBox image.
20
Pop Quiz
What are the 4 attributes to set on all images?
21
Pop Quiz
What are the 4 HTML attributes to set on all images?
src
alt
height
width
22
How do you make an image into a
link?
<a href="https://whitebuffalowebsites.com">
<img src="http://whitebuffalowebsites.com/images/logo-small.png"
height="100" width="300" alt="White Buffalo Logo">
</a>
23
Organizing your Image Files
Just like our website folders and files, we need to
keep the image files organized.
The following are coding conventions used by web
developers.
● Place your images in a folder called, “images”
● The images folder should be at the root
directory of the website, i.e. the images folder
is at the same level as the index.html file.
● Use all lowercase letters. You may need to
change photo file names to all lowercase.
● Do not use punctuation symbols and spaces
except the hyphen (-). Even if you have a messy room, you need
to keep your website files organized.
● Put a hyphen between words (for SEO)
● Never use spaces in the file names
● Do not change the file extensions
(usually .jpg, or .png)
Image URLs
https://isthisanagate.com/images/wordfind.png
On the URL above, first it is the https://, then the domain name,
then the images folder, and lastly, the file name of the image.
Image Permissions
You need to have the rights to any image that you use on your website. Some
Google images cannot be used at all, and some only used can be with attribution.
Here are links to where you can find free and low cost images.
● Pixabay.com
● Freeimages.com
● 123rf.com: low-cost Royalty Free images
If you use images from images.google.com, you need to check to see if it may be
used, and, if so, check to see what attribution is required.
26
Favorites Icon = the Favicon
If you miss one of the three properties, the border will not display.
Pop Quiz
What are the three CSS properties required to display a
border?
Pop Quiz
What are the three CSS properties required to display a border?
border-width
border-color
border-style
div{
border: 12px solid #A51D01;
}
With the shorthand for border, you can attach all three values
into one property.
● If you miss one of the three property values, your border
won't appear. The order doesn't matter.
● Put a space between each of the three values.
● It is called a "shorthand" because you don't have to
separately type in the three border property:value
combinations. But you do need to remember to include all
three values.
Single border lines
You can place a border on only one side with these
properties:
● border-bottom
● border-left
● border-right
● border-top
Example of border-bottom
Note that
when you
change the
H1 to an
inline
element that
the image
pops up next
to it, if there
is room.
Padding
The Box Model
img{
border: 5px solid purple;
padding: 20px;
}
Pixels or Percent for Padding
You can use a numeric value in pixels (px) or EMs (em) or
a percentage (%).
● padding-top:5px;
● padding-right:5%;
● padding-bottom:1em;
● padding-left:5px;
You can also set padding for only one side at a time, eg. padding-right.
padding Shorthand "Around the clock"
50
JSFiddle Solution
h1 {
border: 3px solid red;
border-radius: 5px;
}
53
border-radius examples
You can set each corner to a
different radius with the
border radius shorthand.
54
Demo: Border Radius 4.5
56
JSFiddle Solution
1. horizontal offset
2. vertical offset
3. blur radius
4. color
See the box
shadow around
the blue border?
59
CSS Generator: Box Shadow
Does the box-shadow property seem to
complicated to remember? When you need a box
shadow, just Google, "CSS Generator Box Shadow", and
you will find some nice options.
Here is one:
https://cssgenerator.org/box-shadow-css-generator.html
We need a box-shadow for the Pacific Trail exercise this
week. We'll just use a CSS generator to create the code
for one.
60
CSS Generators
The code is complicated for some other properties described in chapter
4. The good news is that you don't need to remember the code,
because helpful developers have made it easy with CSS generators.
The best CSS generator is a moving target. So when you need a CSS
gradient, box-shadow, or text-shadow, just google it:
CSS Generator Gradient
CSS Generator Box-Shadow
CSS Generator Text-Shadow
The developers who make CSS generators do it for advertising
revenue, so be careful clicking on links as you use them.
Just for fun...make a sprite
Go to https://www.piskelapp.com
Create a Sprite. Export it as a gif.
Add the sprite you make to your template
file for 5 bonus points. An animated gif
The default size
can be installed on a website just like an
is a little small:
embedded image, eg. <img
32px by 32px.
src="images/animated.gif"
Try increasing
height="200" width="200" alt="gif">
the size to 200
Tell me in the Assignment folder comments x 200 px.
to look for it or show me in class.
You can see the pixel art of your This is
classmates on this blog post. Let me know the
if you want me to include yours. button to
https://webdevstudents.com/pixel-art/ export it
when you
are done.
Background Images in CSS
Remember? Two Ways To Add Images
body {
background-image:url(images/background1.jpg);
}
Additional CSS Properties
For background images to work properly, we need some
additional CSS properties, including:
background-repeat
background-size
CSS background-repeat Property
For the background-repeat property, the default behavior is to repeat
the image over and over. Because of that, we need to add this
property/value to most background images:
background-repeat: no-repeat;
CSS background-size Property
Background-size: cover;
Covers the entire background area selected without distorting the image. The entire
image will not likely be shown, unless it is coincidentally the same size as the element
selected. This is the option used most frequently for background photos.
background-size: contain;
Makes the image as large as it can be while showing the full image. This option will leave
some empty space behind the image.
This example
demonstrates
what happens if
there is a
background
image but the
developer doesn't
set it to no-
repeat.
Example 2: no-repeat
This example
demonstrates
what happens if
there is a
background image
and the developer
uses background-
size: no-repeat. As
you can see, the
image only
displays one time.
Example 3: no-repeat and contain
This example
demonstrates what
happens if there is a
background image
and developer sets
the the background-
size to cover. Note
that the image is
stretched to fit and is
pixelated, since it is
too small for the
background.
However, it is not
distorted as with
100% 100%.
1. Open JSFiddle.net
2. Find a background image on Google images or use this url:
https://webdevstudents.com/wp-content/uploads/2022/09/hd-wallpaper-2468874_1280-300x300.jpg
74
JSFiddle Solution
75
Lab
What is a "hero" image?
For the Pacific Trails lab, if the images folder isn't in the pacific folder, then your website won't
show the images. Make sure your images are in the right place in the websites/pacific/images
folder. If you didn't use the starter files in Lab 2, you need to get them now. (Be careful not to
overwrite the work you have already done.)