Background in CSS
CSS background properties are used to define background effects for elements. Background properties in CSS include:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
Background color
The backgroud-color feature defines the background color for the element.
body {
background-color: lightblue;
}
Colors in CSS are usually determined by
- color name, like 'red' .
- HEX color values, like # ff0000 .
- RGB value, like rgb (255,0,0) .
In the example below, the elements
,
and
There are different background colors.
h1 {
background-color: green;
}
div {
background-color: lightblue;
}
p {
background-color: yellow;
}
Background
The background-image
takes the image as the background for the element. By default the image will be duplicated to cover the entire element.
body {
background-image: url("paper.gif");
}
Note that when using the image as a background, do not let it insert or make the text difficult to read.
Repeating vertical and horizontal background images
By default, the background-image
will be repeated both horizontally and vertically to cover the entire element. Some photos should only be repeated in one direction, otherwise they will look very bad. Then use the background-repeat: repeat-x;
to repeat horizontally and background-repeat: repeat-y;
to repeat vertically.
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}
Background image, set position and no repeat
To get an image as a background and do not want to repeat it, use the background-repeat.
body {
background-image: url("img_trejpg");
background-repeat: no-repeat;
}
Images appear once on the page
The example on the picture appears only once and appears in the same place as the text. So we should change the image position with the background-position.
body {
background-image: url("img_tree.jpg");
background-repeat: no-repeat;
background-position: right top;
margin-right: 200px;
}
Images no longer insert text when changing positions
Background image, fixed position
To specify a fixed background image (without scrolling along the whole page), use the background-attachment.
body {
background-image: url("img_tree.jpg");
background-repeat: no-repeat;
background-position: right top;
background-attachment: fixed;
}
When scrolling the page, the image remains in its original position
Background image, shortened feature
To shorten the code, you can specify all properties for the background in a single property, this is called a shortened feature. The shortened feature of the background.
is the background.
body {
background: #ffffff url("img_tree.jpg") no-repeat right top;
}
When using the shortened feature, the order of values will be
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
Just write in the right order, not necessarily full of features.
Last lesson: Colors in CSS
The following article: Contour in CSS
You should read it
- Instructions to delete online background images for free
- Bring the cool background image separation feature on iPhone to Samsung phones
- The divine tool separates the photo background with just a click of the mouse that is available on Photoshop CC
- How to replace art background image with PicsArt
- Synthesis most luxurious background
- How to Add Background Graphics to Powerpoint
- Cute Background, download Cute Background here
- 7 best websites to find images with transparent backgrounds
May be interested
- What is the best AI photo background remover?people spend too much time manually removing backgrounds, and ai isn't always the magic it claims to be.
- Synthesize the most beautiful CSS Background Gradient templatesingle color was the trend of last year. gradient is currently 'on the throne'! but do you know how to create a background gradient in css?
- How to Add Background Graphics to Powerpointthe format background utility in powerpoint allows you to select an image from your computer or online to use as the background for your slide. you can set this background to multiple slides at once, or apply it to your entire...
- Cute Background, download Cute Background herecute background. are you looking for cute background templates for collages or wallpapers but still can't find a picture you like? with the cute background collection in this article will help you find the right images.
- How to change the background in Illustratorwhen working in illustrator, you may feel the need to change the background to make it easier to develop layers and effects. a transparent background works well for pngs, while you may want a different tone to highlight the lines.
- Beautiful Landscape Background, download Beautiful Landscape Background herebeautiful landscape background. are you looking for beautiful landscape background templates to make photo collages or powerpoint backgrounds? with the landscape background samples in the article below, you will have diverse and rich choices.
- Let your photos 'shine' with GIMP's background change featureit's easy to change the backgound of a photo in photoshop, but you don't want to pay the expensive cost for that, so gimp will be a wise choice. changing the background in gimp is very simple and there are many different ways to do this. the following article will introduce two best solutions to help your photos 'shine'.
- How to delete a background color in a Word document?it's helpful to dump the background color in the field so you can easily find the fields in your document. however, if you share documents with others or use them in a presentation ... you should remove the background color.
- How to turn off applications that run in the background on Windows 10turning off the application running in the background on windows 10 will make the computer less sluggish, saving system resources. the following article of network administrator will guide you how to turn off applications running in the background on windows 10.
- How to split video background, GIF image on Unscreenunscreen will separate the video background and animation so you can change the other background if you like, it's free and doesn't need an account.