Styling Background in CSS
- Styling Background Using CSS
- Backgrounds are a core part of CSS. They are one of the fundamentals that we simply need to know.
-
We have five main background properties to use in CSS 2.
-
background-color: specifies the solid color to fill the background with.
-
background-image: calls an image for the background.
-
background-position: specifies where to place the image in the element’s background.
-
background-repeat: determines whether the image is tiled.
- background-attachment: determines whether the image scrolls with the page.
- Background Color
-
The background-color property fills the background with a solid color. There are a number of ways to specify the color. The following commands all have the same output:
-
background-color: blue;
-
background-color: rgb(0, 0, 255);
-
background-color: #0000ff;
- Background Image
- The background-image property allows us to specify an image to be displayed in the background.
background-image: url(‘path to image’);
- Background Repeat
-
By default, when we set an image, the image is repeated both horizontally and vertically until the entire element is filled.
But sometimes we want an image to be displayed only once or to be tiled in only one direction.
The possible values are:
- repeat;
- no-repeat;
- repeat-x;
- repeat-y;
- inherit;
Background Position
The background-position property sets the starting position of a background image.
Possible values:
-
left top
-
left center
-
left bottom
-
right top
-
right center
-
right bottom
-
center top
-
center center
-
center bottom
-
x% y%
-
xpos ypos
- inherit