Home > Article > Web Front-end > Specific analysis of the background attribute in CSS
Let’s start with a simple Specific analysis of the background attribute in CSS setting:
#show-box { width: 800px; height: 500px; Specific analysis of the background attribute in CSS: #000; Specific analysis of the background attribute in CSS-image: url(image url); } </style>
Here we simply set the color and Specific analysis of the background attribute in CSS texture.
Let’s take a look at the official Specific analysis of the background attribute in CSS attributes:
Syntax format:
Specific analysis of the background attribute in CSS: color position size repeat origin clip attachment image;
Note: If the two attributes "position" and "size" are set at the same time, you should use a left slash "/" instead of using spaces to separate the two parameter values. Separate: "position/size".
1 Specific analysis of the background attribute in CSS: url("img.jpg") center center/100% 100% no-repeat;
Attribute table (the image may be displayed too small, please right-click "Open in new tab" to view the original image):
Optional value: The default is transparent, other values can be set by viewing the "CSS Color Value Table".
<style> #show-box { width: 180px; height: 180px; border: 20px dashed #000; Specific analysis of the background attribute in CSS-color: #000000; Specific analysis of the background attribute in CSS-color: blue; Specific analysis of the background attribute in CSS-color: rgb(255, 255, 255); Specific analysis of the background attribute in CSS-color: rgba(255, 255, 255, 0.8); } </style>
Optional values: two parameters, horizontal position and vertical position. If there is only one value, the second value is "center".
The default value is the upper left corner of the element. Positional keywords (top, right, bottom, left, center) can be used. Percent (based on element size). Pixel values.
<style> #show-box { width: 180px; height: 180px; border: 20px dashed #000; Specific analysis of the background attribute in CSS-position: center; Specific analysis of the background attribute in CSS-position: center top; Specific analysis of the background attribute in CSS-position: 0 100px; Specific analysis of the background attribute in CSS-position: 10% 20%; } </style>
Optional values: two values. If there is only one value, the second value is auto.
The default is the size of the image itself. You can use pixel values, percent (based on the element size).
Cover: Scale the image proportionally to cover this element. Similar to the "fill" of the desktop Specific analysis of the background attribute in CSS in Windows.
Contain: Scale the image proportionally to adapt to the width or height of the element. Similar to the "adaptation" of the desktop Specific analysis of the background attribute in CSS in Windows.
Repeat: Completely tile, copy the image to fill the entire element. (Default)
Repeat-x: Tile horizontally, copy and tile in the horizontal direction.
repeat-y: vertical tile, copy and tile in the vertical direction.
no-repeat: No tiling, only use one image.
Optional values: border-box, padding-box, content-box.
Optional values: border-box, padding-box, content-box.
Compare the renderings of different values:
1. origin: border-box; clip: border-box;
<style> #show-box { width: 180px; height: 180px; margin: 20px; padding: 20px; border: 20px dashed #000; Specific analysis of the background attribute in CSS: url("img.jpg") no-repeat border-box border-box; } </style>
2.origin:padding-box;clip:border-box;
<style> #show-box { width: 180px; height: 180px; margin: 20px; padding: 20px; border: 20px dashed #000; Specific analysis of the background attribute in CSS: url("img.jpg") no-repeat padding-box border-box; } </style>
4.origin:border-box;clip:content-box;
<style> #show-box { width: 180px; height: 180px; margin: 20px; padding: 20px; border: 20px dashed #000; Specific analysis of the background attribute in CSS: url("img.jpg") no-repeat content-box border-box; } </style>
It can be seen that origin sets the position, and clip will crop the Specific analysis of the background attribute in CSS image according to the area. 7.attachment: Set whether the Specific analysis of the background attribute in CSS image is fixed or scrolls with the rest of the page.
The default value is scroll: the Specific analysis of the background attribute in CSS image scrolls with the rest of the page. fixed: The Specific analysis of the background attribute in CSS image is fixed.
8. Multiple Specific analysis of the background attribute in CSS settings. Import images: Specific analysis of the background attribute in CSS-image: url(image url); 2. Multiple Specific analysis of the background attribute in CSS settings. How to write multiple Specific analysis of the background attribute in CSSs: separate them with commas "," and continue writing the Specific analysis of the background attribute in CSS attributes. Background:color position size repeat origin clip attachment image,
color position size repeat origin clip attachment image; Specific attributes can also be set individually :Specific analysis of the background attribute in CSS-image: url(image url 1), url(image url 2);<style> #show-box { width: 180px; height: 180px; margin: 20px; padding: 20px; border: 20px dashed #000; Specific analysis of the background attribute in CSS: url("img.jpg") no-repeat border-box content-box; } </style>
<style> #show-box { width: 180px; height: 180px; border: 20px dashed #000; Specific analysis of the background attribute in CSS: url("img.jpg1") left top/100% 100% no-repeat, url("img.jpg2") left center/100% 100% no-repeat, url("img.jpg3") left bottom/100% 100% no-repeat, url("img.jpg4") center top/100% 100% no-repeat; } </style>
The above is the detailed content of Specific analysis of the background attribute in CSS. For more information, please follow other related articles on the PHP Chinese website!