Background color (Background-color)
CSS can be used as a background with a solid color, or the background can be set to transparent, background equivalent to bgcolor in XHTML.
It's two values:
- Transparent (default, transparent)
- Color (The specified color, and the text color is set in the same way)
Example:
body {background-color:black;}
H1 {background-color: #00ff00;}
h2 {background-color:transparent;}
P {Background-color:rgb (0,0,255);}
Background picture (Background-image)
Using a picture as the background of the label can be used to this property, if the background color and background image are defined, the background image will be covered by the background color.
Example:
Body {Background-image:url (.. /images/background.jpg);}
Or
<body style= "Background-image:url (.. /images/background.jpg); " >
Background repeating property (Background-repeat)
This property must be followed by the Background-image attribute, which determines the repeating method of the picture background. If you do not add this property after using Background-image, it is repeated horizontally vertically by default, and it has four property values:
- Repeat (default, repeat, Landscape and portrait.) )
- No-repeat (non-repeating)
- Repeat-x (background picture is repeated horizontally)
- Repeat-y (background picture repeats vertically)
Example:
Body {
Background-image:url (.. /images/background.jpg);
Background-repeat:repeat-y; /* Repeat vertically */
}
Background Position Property (background-position)
This property is also used after the Background-image property, which determines the initial position of the background image, which is usually located in x and y coordinates, so usually takes two values, the default value is 0% 0%.
It deploys 8 attribute values in a horizontal, vertical manner:
- Level: Left, center, right;
- Vertical: Top, center, bottom;
- Vertical and horizontal synthesis: x-% y-%, X-pos y-pos.
The first 6 attribute values are simple, and the last two attribute values can be somewhat confusing at first glance. x-% y-% means the percentage of the x-axis and the percentage of the y-axis, x-pos y-pos means the value of the x-axis and the y-axis.
Example:
p {
Background-image:url (.. /images/background.jpg);
background-position:20px-30px;
Background-repeat:no-repeat;
}
div {
Background-image:url (.. /images/background.jpg);
background-position:50% 20%;
Background-repeat:no-repeat;
}
Background Attachment property (background-attachment)
This property is still followed by Background-image, which determines whether the background image scrolls along with the content or is fixed, and it has two attribute values:
- Scroll (default, background picture follows content scrolling. )
- Fixed (the background image is pinned and does not follow the content scrolling.) )
Example:
. para6 {
Background-image:url (.. /images/background.jpg);
background-position:50% 20%;
Background-repeat:no-repeat;
background-attachment:fixed;
}
Background properties (background)
As with the font properties mentioned in the previous articles, background is also a comprehensive abbreviation for the Order of writing:
Background:background-color background-image background-repeat background-attachment background-position;
Example:
. para7 {
Background: #000000 URL (... /images/background.jpg);
}
. para8 {
Background:url (.. /images/background.jpg) repeat fixed left top;
}
How to use the Background property background under CSS