Home Web Front-end CSS Tutorial Summary of the use of background attributes in css

Summary of the use of background attributes in css

Jun 08, 2017 am 11:48 AM

backgroundThe background attribute is an important attribute in CSS. You can use the background attribute to set various styles of a background element, including setting the color of the filled background, using your own picture as the background, so that the picture will repeat horizontally and vertically until it covers the entire element, and controlling the position of the background picture in the element. etc. Using pictures as backgrounds is often encountered in a web page layout. Generally, setting the object picture as the background attribute instance first sets the background color, followed by setting the picture as the background, followed by whether the picture is repeated, and then the picture at the object position. The previous background color does not need to be set and is not required. Generally, a picture is used as the object background. If you want to set whether the picture is displayed repeatedly, the distance position will be set. The following content will specifically explain the various uses of the background background attribute.

First of all, you can learn free courses related to php Chinese website

1. Learn"CSS 0 Basic Introductory Tutorial" in CSS Background Chapter Course

CSS 0基础入门教程

##2. Watch the Background and Margin video course in "Dark Horse Programmer CSS Video Tutorial"

Summary of the use of background attributes in css

background background property

1.

CSS knowledge that must be mastered-background property

Summary of the use of background attributes in cssWhen we set the border for the body, we will find that the border only encloses the content in the body. But setting the background color for the body fills the entire screen.

When using an image as the background, the image is positioned with reference to the visible area of ​​the screen, not the part framed by the border.

Each parameter is separated by spaces, followed by color, picture, repetition, fixation method, and position.

2.

Background related attributes in css

Percent/length: If it is a percentage, the size of the background image is the product of the container times the percentage. Set only one, and set the second one to auto (to maintain the same aspect ratio as the original background image).

If both are set to 100%, the background image will fill the container, but the aspect ratio will change.

contain: The container contains the entire background image according to a fixed proportion of the background image. The size of the background image is enlarged by a fixed ratio based on the background image. Until any side reaches the boundary of the container, the other side will often be blank (when there is no-repeat).

cover: The background image is enlarged according to a fixed aspect ratio until it fills the entire container (the shorter side of the background image also reaches the container boundary). Part of the background image will be cut off because it exceeds the container.

3.

Detailed explanation of the background attribute of css

In the same element, the background composite attribute is written at the front, and the background attribute that needs to be set individually is written at the end; reason : The front wave of the Yangtze River pushes back the wave, and the front wave dies on the beach.

Multiple background images are added to the same element. Other background attributes can only be written separately, and composite attribute abbreviations cannot be used;

in In nested parent-child elements, it is not recommended to write attributes with the same name. Reason: When the size of the child element is greater than or equal to the size of the parent element, the style of the parent element will be overwritten by the child element;

In actual work, use more background images and less use of inserted pictures.

4.

Detailed explanation of the new background series background in CSS3

border-box: Ignore the border and start tiling directly from the starting point 0,0 of the border padding-box: Default value, ignore padding, and start tiling directly from the starting point 0,0 of padding. content-box: start tiling from the content part, and the padding position will be reserved. So padding will affect it

5. How to set the css background image and background color in the web page

CSS background here refers to setting the background properties of the object through CSS, such as setting the background through CSS in the web page. style.

Css background Background function: Set a solid color background. Background background can set the background color of the object to a solid color and set the image as the background. You can set the background of the object to a picture. If the background is a picture, you can make the picture tile repeatedly or horizontally, or fix the picture as the background of the object at any position of the object.

6. Summary sharing of CSS background attributes and CSS3 background image settings

background Set all background attributes in one statement

background- attachment Sets whether the background image is fixed or scrolls with the rest of the page

background-color Sets the background color of the element

background-image Sets the background image of the element

background- position Set the starting position of the background image

Related questions and answers

1. How to speed up the loading speed of css background images

2. Can’t background:unset be used on ios? So what do you do if you want to cancel the background color?

3. body’s background position

[Related recommendations]

1. PHP Chinese website free tutorial: 《CSS Online Manual》

2. PHP Chinese website free video tutorial: 《Learn HTML video tutorial at your fingertips》

3. PHP Chinese website free video tutorial: 《php.cn Dugu Jiujian (2)-css video tutorial》

The above is the detailed content of Summary of the use of background attributes 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)

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 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.

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 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 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 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