Table of Contents
1. The Specific analysis of the background attribute in CSS attribute can set the Specific analysis of the background attribute in CSS style of an element. Of course, the premise is that the element has a specific width and height value.
 1.color: Specific analysis of the background attribute in CSS color value. This attribute will add color to the entire element and is at the bottom (this can be seen if there is a Specific analysis of the background attribute in CSS image).
 2.position: the positioning of the Specific analysis of the background attribute in CSS image. If there is no image setting, then this attribute has no effect.
 3.size: Image size. Applied to pictures.
 4.repeat: tiling method.
 5.origin: the reference area of ​​the Specific analysis of the background attribute in CSS.
 6.clip: The visible area of ​​the Specific analysis of the background attribute in CSS.
Home Web Front-end CSS Tutorial Specific analysis of the background attribute in CSS

Specific analysis of the background attribute in CSS

Jul 21, 2017 am 09:08 AM
background css

1. The Specific analysis of the background attribute in CSS attribute can set the Specific analysis of the background attribute in CSS style of an element. Of course, the premise is that the element has a specific width and height value.

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>
Copy after login

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;
Copy after login

Attribute table (the image may be displayed too small, please right-click "Open in new tab" to view the original image):

 Specific analysis of the background attribute in CSS

 1.color: Specific analysis of the background attribute in CSS color value. This attribute will add color to the entire element and is at the bottom (this can be seen if there is a Specific analysis of the background attribute in CSS 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>
Copy after login

 2.position: the positioning of the Specific analysis of the background attribute in CSS image. If there is no image setting, then this attribute has no effect.

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>
Copy after login

 3.size: Image size. Applied to pictures.

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.

 

 4.repeat: tiling method.

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.

 5.origin: the reference area of ​​the Specific analysis of the background attribute in CSS.

Optional values: border-box, padding-box, content-box.

 6.clip: The visible area of ​​the Specific analysis of the background attribute in CSS.

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>
Copy after login

     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>
Copy after login

   

  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>
Copy after login

  

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>
Copy after login
<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>
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

See all articles