Select Lesson
Anchor Styles Quiz
5 min
Image width & height in CSS width:
, height:
, max-width:
5 min
Border
5 min
Individual borders for a side
5 min
Color names
2 min
RGB colors —rgb(r,g,b)
3 min
RGB Colors Quiz
5 min
Hex colors —#RRGGBB
3 min
HEX Colors Quiz
5 min
HSL colors —hsl(hue, saturation, lightness)
5 min
Adobe color panel
2 min
ColorZilla
3 min
Lesson 16. Image borders
15 min
Image Styles Quiz
5 min
Review Quiz 2
5 min
Some other fun links
5 min
Image & Color CSS
Level OneAnchor Styles Quiz
5 min
Image width & height in CSS width:
, height:
, max-width:
5 min
Border
5 min
Individual borders for a side
5 min
Color names
2 min
RGB colors —rgb(r,g,b)
3 min
RGB Colors Quiz
5 min
Hex colors —#RRGGBB
3 min
HEX Colors Quiz
5 min
HSL colors —hsl(hue, saturation, lightness)
5 min
Adobe color panel
2 min
ColorZilla
3 min
Lesson 16. Image borders
15 min
Image Styles Quiz
5 min
Review Quiz 2
5 min
Some other fun links
5 min
60 min
Image styles and color
How to add CSS to format images and a bit about how color works in CSS
Code Avengers Quiz
Anchor Styles Quiz
Concepts
Image width & height in CSS width:
, height:
, max-width:
The width
property specifies the width of an element, and the height
property specifies the height of an element.
There are actually two ways to set the size of an image: using the img
tag attribute or using a CSS property.
HTML
This sets the width of an image using the img
tag attribute:
<img src="/image/default.png" width="115">
CSS
This CSS code sets the width of all images on the page using a CSS property:
img {
width: 115px;
}
There is also a max-width
property.
It is very useful for small screens. It will set the width but if the screen is smaller than the width, the image will adjust.
(The value of the max-width
property overrides width
.)
The img
tag attribute doesn't need a measurement, like px, on the end, but the CSS rule does.
If you add the img
tag attribute and the CSS rule, the CSS rule is used.
You can set the length with many different values.
- pixels (px),
- percentage of the container (%)
- centimeters (cm)
- auto (original size)
There are a lot more here
width: auto
, height: auto
width: 150px
, height: auto
width: 100%
, height: 133px
Remember that % is the percentage of the container it fills up.
50% means "fill the half containers width." NOT set image to half its real size, as you might expect.
Concepts
Border
A border is added to an image by setting the border-style
property to solid
.
The width of a border can be set with the border-width
property.
The color of a border can be set with the border-color
property.
Example:
img {
border-color: tan;
border-style: ridge;
border-width: 10px;
width: 150px;
}
This is the shorthand for border style.
border:width style color;
The three values you can change are:
- width:px, mm, in
- style:
solid
,dotted
,dashed
,double
,groove
,ridge
,inset
,outset
andnone
. - color: steelBlue, rgb(123,128,147), #7B8093 etc
Here are some examples:
Concepts
Individual borders for a side
You can control individual sides with border-top
, -bottom, -right or -left.
You can write it the long way
img{
border-top-style:dotted;
border-top-width:10px;
border-top-color:tomato;
}
or use shorthand
img{
border-top:10px dotted tomato;
}
The CSS that is written last will take effect (as long as they have the same specificity , which these all have).
Example:
Concepts
Color names
140 color names are defined in the HTML and CSS color specification
(17 standard colors plus 123 more).
The table below lists them all:
For Example
You can play around with the color names table → in the project IDE.
Heads Up!
These tools can all be accessed through the TOOLBOX inside the Code Avengers Lessons.
Concepts
RGB colors —rgb(r,g,b)
The CSS colors "gray", "blue", or "purple" can be boring and limiting.
You can define your own custom color using rgb
color values.
An RGB value is the intensity of red, green, and blue used to make a color.
Each intensity value is on a scale of
0 to 255
, you can also use percent out of 100.
For example:
rgb(0,0,0)
is Black and
rgb(255,255,255)
/rgb(100%,100%,100%)
is White.
rgb(255,0,0)
/rgb(100%,0,0)
is Red,
rgb(0,255,0)
orrgb(0,100%,0)
is Green and
rgb(0,0,255)
orrgb(0,0,100%)
is Blue.
- slateBlue has these RGB values
rgb(106,90,205)
.
- slateBlue has these RGB values
There is a 4th value that can be added, alpha
to rgba color values to specify
transparency
.
Alpha is between 0(completely transparent) to 1 (completely opaque). So 0.5 is semi-transparent.
For Example
Try the RGB color values table
Heads Up!
These tools can all be accessed through the TOOLBOX inside the lessons.
Code Avengers Quiz
RGB Colors Quiz
Concepts
Hex colors —#RRGGBB
The red, green, and blue intensity can also be valued using hexadecimal from 00 to FF (0-255 in RGB).
There are six digits, in three pairs for the colors #RRGGBB. Each digit goes from 0-15 (A-F replace the decimal numbers 10-15).
The hex number for black is #000000 and #FFFFFF are the values for white.
0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
For Examples
Try the HEX color mixer to mix and match your own hex values.
Try the HEX & RGB Color widget >> to see the two different color values together.
There is more information on hexadecimals in the extension work.
Code Avengers Quiz
HEX Colors Quiz
Concepts
HSL colors —hsl(hue, saturation, lightness)
HSL colors are RGB colors rearranged in a model designed to be more intuitive to use and more relevant.
hsl(hue, saturation, lightness)
color: hsl(0, 100%, 50%); /*HSL color value for pure red.*/
HSL uses three values:
Hue
Hue is the "pure" color. The values are degrees on the color wheel; 0 (or 360) is red, 120 is green, 240 is blue. The degrees in between are a pure mix of those colors.
Name | Degrees | Color |
---|---|---|
Red | 0° | |
Yellow | 60° | |
Green | 120° | |
Cyan | 180° | |
Blue | 240° | |
Purple | 300° |
Saturation
Saturation uses a percentage; 0% is gray and 100% is full colour. Saturation determines the ratio of colorfulness to brightness. (A basic use is to make color duller or more vivid).
Percent: | 0% | 20% | 40% | 60% | 80% | 100% |
---|---|---|---|---|---|---|
Saturation |
Lightness
Lightness asks how bright is it compared to the brightness of a white with the same values? 0% is dark (black), 100% is light (white), and 50% is the average (the one you will want for a pure hue).
This is how you get your tints and shades- lighter and darker versions of a color.
Percent: | 0% | 20% | 40% | 60% | 80% | 100% |
---|---|---|---|---|---|---|
Lightness |
Alpha channel (optional)
Like RGBa, HSLa has an optional alpha channel that controls the opacity (solidness) of a color. Again it is a number between 1 and 0 with 0.5 being semi-transparent.
background-color: hsla(0,100%,0%,0.2)
Concepts
Adobe color panel
The Adobe color panel is a great tool for picking a color group when you don't know what color goes with what.
color.adobe.com is a tool used by web designers to create and share color schemes.
Concepts
ColorZilla
ColorZilla is a great website that has two features.
- An eyedropper to select the values of a color on your screen and
- A super easy gradient tool that then generates the CSS code for you to easily copy and apply to your buttons or backgrounds or what ever you need!
Try http://www.colorzilla.com, it is so easy to get color schemes!
Heads Up!
The eyedropper is a plugin so if you using Code Avengers at school or at work you may not have permissions to install it. You may need to email your IT admin for them to install it if you are unable too
HTML/CSS 1 Lesson
Lesson 16. Image borders
Code Avengers Quiz
Image Styles Quiz
Code Avengers Quiz
Review Quiz 2
Extension: Concepts
Some other fun links
Resources
Guide
- download
- new file
- upload media
- rename
- delete
Run Ctrl+Enter
Check Ctrl+Shift+Enter
Reset Ctrl+Backspace
Redo Ctrl+Y
Cut Ctrl+X
Copy Ctrl+C
Paste Ctrl+V
Find Ctrl+F
Find & replace Ctrl+F+F