background Flashcards
What do background properties effect?
The background of the selected element/container
background-color
Fills the container with a specified color
opacity
Specifies the opacity/transparency of an element. Values 0.0 -> 1.0
background-image
Specifies the background image of an element with a URL
body {
background-image: url(“myImage.jpg”);
}
What is the default setting for a background image?
Placed top-left and repeated [V and H], so it covers the entire element.
How many background images can you have?
As many as you’d like.
Should you set a background-color if you already have a background-image?
Yes, in case the image fails to load.
What background properties can you set with one declaration?
body {
background: lightblue url(“img_tree.gif”) no-repeat fixed center;
}
The background property is a shorthand property for:
background-color
background-image
*background-position/background-size
background-repeat
background-origin
background-clip
background-attachment
*must be position/size
background-origin
sets the starting point for the background image.
padding-box //default starts from upper left padding
border-box //image starts from upper left border
content-box //image starts from the upper left corner of the content
inherit //inherit origin from the parent element
background-position
Specifies the origin of the image
horizontal% vertical%;
horizontalpx verticalpx
inherit
left || right combined with [top, center, bottom]
background-repeat
Specifies how to repeat the background
repeat //default x and y
repeat-x //only horizontally
repeat-y //only vertically
no-repeat
space, round, inherit
background-size
background-size: auto|length|cover|contain|initial|inherit;
x% y%
background-attachment
How a background image is set to the document
scroll //default will scroll with the page
fixed // will not scroll
local // scrolls with the element’s content
Does background have a shorthand property?
Yes, can contain many properties with one declaration…
background: color image repeat origin
body {
background: #ffffff url(“img_tree.png”) no-repeat right top;
}