search
HomeWeb Front-endCSS TutorialSummary of the use of background attributes in css

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
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
利用CSS怎么创建渐变色边框?5种方法分享利用CSS怎么创建渐变色边框?5种方法分享Oct 13, 2021 am 10:19 AM

利用CSS怎么创建渐变色边框?下面本篇文章给大家分享CSS实现渐变色边框的5种方法,希望对大家有所帮助!

css ul标签怎么去掉圆点css ul标签怎么去掉圆点Apr 25, 2022 pm 05:55 PM

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

css与xml的区别是什么css与xml的区别是什么Apr 24, 2022 am 11:21 AM

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

css3怎么实现鼠标隐藏效果css3怎么实现鼠标隐藏效果Apr 27, 2022 pm 05:20 PM

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

rtl在css是什么意思rtl在css是什么意思Apr 24, 2022 am 11:07 AM

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

css怎么实现英文小写转为大写css怎么实现英文小写转为大写Apr 25, 2022 pm 06:35 PM

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

css怎么设置i不是斜体css怎么设置i不是斜体Apr 20, 2022 am 10:36 AM

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

怎么设置rotate在css3的旋转中心点怎么设置rotate在css3的旋转中心点Apr 24, 2022 am 10:50 AM

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)