Longhand Properties of CSS Background
Longhand Properties of CSS Background
Created: 2022-10-07
A background-color extends underneath the content and padding box of the element.
Adds background-image
In the example below, we have two boxes — one has a background image which is larger than the box (balloons.jpg),
the other has a small image of a single star (star.png).
.box {
background-image: url(star.png);
https://developer.mozilla.org/en-US/docs/Web/CSS/gradient
.a {
.b {
background-image:
url(image1.png),
url(image2.png),
url(image3.png),
url(image4.png);
top right;
Question: What happens when different properties have different numbers of values?
Above example has FOUR background images but only TWO background-position values.
length
percentage
cover — the browser will make the image just large enough so that it completely covers the box area while still
retaining its aspect ratio.
contain — the browser will make the image the right size to fit inside the box.
uses a coordinate system in which the top-left-hand corner of the box is (0,0) , and the box is positioned along the
horizontal ( x ) and vertical ( y ) axes.
4 value syntax
.box {
background-repeat: repeat;
fixed :
1. Doesn't scroll when the page or element content is scrolled. Causes element's background to be fixed to the
viewport
scroll :