Lesson 10 Colours Continue
Lesson 10 Colours Continue
Objectives:
learn about the CSS background properties
Outcomes:
Styling components in CSS
Notes:
The CSS background properties are used to add background effects for
elements.
background-color
background-image
background-repeat
background-attachment
background-position
background (shorthand property)
CSS background-color
The background-color property specifies the background
color of an element.
Other Elements
You can set the background color for any HTML elements:
Opacity / Transparency
The opacity property specifies the opacity/transparency
of an element. It can take a value from 0.0 - 1.0. The
lower value, the more transparent:
Note: When using the opacity property to add
transparency to the background of an element, all of
its child elements inherit the same transparency. This
can make the text inside a fully transparent element
hard to read.
You learned from our CSS Colors Chapter, that you can
use RGB as a color value. In addition to RGB, you can
use an RGB color value with an alpha channel (RGBA) -
which specifies the opacity for a color.
An RGBA color value is specified with: rgba(red, green,
blue, alpha). The alpha parameter is a number between
0.0 (fully transparent) and 1.0 (fully opaque).
CSS background-image
The background-image property specifies an image to
use as the background of an element.
By default, the image is repeated so it covers the entire
element.
Note: When using a background image, use an image
that does not disturb the text.
CSS background-position
The background-position property is used to specify the
position of the background image.
CSS Background Attachment
CSS background-attachment
The background-attachment property specifies whether
the background image should scroll or be fixed (will not
scroll with the rest of the page):
CSS Background Shorthand
CSS background - Shorthand property
To shorten the code, it is also possible to specify all the
background properties in one single property. This is
called a shorthand property.
Instead of writing:
You can use the shorthand property background:
<body>
<h1>This is a heading</h1>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
</body>