search
HomeWeb Front-endCSS TutorialDetailed explanation of the background attribute of css style

background Detailed explanation of usage:

1, background-color AttributeSet the background color of the element

Possible Value

color_name Specifies that the color value is the background color of the color name (such as red)

hex_number Specifies that the color value is a hexadecimal value Background color (such as #ff0000)

rgb_number Specifies that the color value is the background color of the rgb code (such as rgb(255,0,0)

transparent The default background color is transparent

2, background-image The attribute sets the background of the elementImage

Possible values

Single background image: background-image:url(a.png)

Multiple background images: background-image:url(a.png),url(b.png)

Linear Gradient: background-image:-webkit (-repeating)-linear-gradient(direction, color value in pixels or percentage, color value in pixels or percentage...)

                Direction :left, right,top,bottom,90deg,180deg

                  Color value pixels or percentage: yellow 10%, transparent 4px, rgb(0, 0,0) 2px

Radial gradient: background-image:-webkit(-repeating)-radial-gradient([position> || ,]? [ || ,]? , [, ]*)

                                  -position>: The default is center

                                                                                                                                          ’ ‐ ’ s ’ s ’s ’ s ’ s ’ s ,                                                              to cover

3,

background-size

attributes are used to reset the size of the background image contain: shrink the background image to fit the label element

cover: The background image is enlarged and extended to the entire label element size

Pixels: Indicates the size of the background image scaling

Percentage: The percentage is based on the size of the content label element to scale the size of the image

4,

background-position

The attribute is used to set the background image position Possible values: left, right, top, bottom, center, pixels, percentage

5 ,

background-repeat

attribute is used to set the background image position Possible values: repeat,repeat-x,repeat-y,no-repeat,space (will not be cropped or resized ), round (will not be cropped but will change the image size)

6,

background-attachment

attributes are used to set whether the background image can be scrolled Possible values: scroll, fixed

7,

background-clip

attributes are used to specify the drawing area of ​​the background Possible values: b

ord

er-box,padding-box,content-box8,

background-origin

attributes are used to specify the position relative to which the background-position attribute is positioned Possible Value: border-box, padding-box, content-box

Extension: draw square

html code

<p>使用背景绘制方格,使每个文字都在方格里,效果图如下。</p>

css code

 p {
     width: 300px;
     height: 300px;
     border-left: 3px solid pink;
     border-top: 3px solid pink;
     background-image: -webkit-linear-gradient(180deg, pink 3px, transparent 3px) , -webkit-linear-gradient(90deg, pink 3px, transparent 3px);
     background-size: 30px;
     line-height: 30px;
     font-size:25px;
     letter-spacing: 5px;    
}

result

Use the background to draw a square grid so that each text is in the square grid. The rendering is as follows.

The above is the detailed content of Detailed explanation of the background attribute of css style. 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
Weekly Platform News: Web Apps in Galaxy Store, Tappable Stories, CSS SubgridWeekly Platform News: Web Apps in Galaxy Store, Tappable Stories, CSS SubgridApr 14, 2025 am 11:20 AM

In this week's roundup: Firefox gains locksmith-like powers, Samsung's Galaxy Store starts supporting Progressive Web Apps, CSS Subgrid is shipping in Firefox

Weekly Platform News: Internet Explorer Mode, Speed Report in Search Console, Restricting Notification PromptsWeekly Platform News: Internet Explorer Mode, Speed Report in Search Console, Restricting Notification PromptsApr 14, 2025 am 11:15 AM

In this week's roundup: Internet Explorer finds its way into Edge, Google Search Console touts a new speed report, and Firefox gives Facebook's notification

The Power (and Fun) of Scope with CSS Custom PropertiesThe Power (and Fun) of Scope with CSS Custom PropertiesApr 14, 2025 am 11:11 AM

You’re probably already at least a little familiar with CSS variables. If not, here’s a two-second overview: they are really called custom properties, you set

We Are ProgrammersWe Are ProgrammersApr 14, 2025 am 11:04 AM

Building websites is programming. Writing HTML and CSS is programming. I am a programmer, and if you're here, reading CSS-Tricks, chances are you're a

How Do You Remove Unused CSS From a Site?How Do You Remove Unused CSS From a Site?Apr 14, 2025 am 10:59 AM

Here's what I'd like you to know upfront: this is a hard problem. If you've landed here because you're hoping to be pointed at a tool you can run that tells

An Introduction to the Picture-in-Picture Web APIAn Introduction to the Picture-in-Picture Web APIApr 14, 2025 am 10:57 AM

Picture-in-Picture made its first appearance on the web in the Safari browser with the release of macOS Sierra in 2016. It made it possible for a user to pop

Ways to Organize and Prepare Images for a Blur-Up Effect Using GatsbyWays to Organize and Prepare Images for a Blur-Up Effect Using GatsbyApr 14, 2025 am 10:56 AM

Gatsby does a great job processing and handling images. For example, it helps you save time with image optimization because you don’t have to manually

Oh Hey, Padding Percentage is Based on the Parent Element's WidthOh Hey, Padding Percentage is Based on the Parent Element's WidthApr 14, 2025 am 10:55 AM

I learned something about percentage-based (%) padding today that I had totally wrong in my head! I always thought that percentage padding was based on the

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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools