Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the background property in CSS

Shulou Source: shulou.com Published: 2022-05-31 13:22:10 09月15日 Update

This article mainly explains "how to use the background attribute in CSS". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the background attribute in CSS".

The background attribute is background-color,background-image,background-position,background-attachment,background-repeat, an acronym for these five attributes, which has the advantage of being easier to write than a single attribute and writing a lot less code. It is sometimes a bit confusing in the order in which these five attributes are written. The following code is taken from Sohu:

The code is as follows:

.bBot {background:url (.. / images20130624/bg.png) no-repeat-1424px-5px; overflow:hidden;}

.cBot {background:url (.. / images20130624/sohubg01.png) 0-181px repeat-x;width:758px;height:6px;clear:both;font-size:1px;margin:0 auto;}

The order of the background attribute of the .bBot selector is background-image,background-repeat,backgroundf-position. (background-repeat in front, backgroundf-position in the back)

The order of the background attribute of the .cBot selector is background-image,background-position,background-repeat. (background-position in front, background-repeat in the back)

That is, the CSS of the same company has a different style of writing, so I think it's a little wrong.

Let's take a look at the official definition of the background attribute of CSS:

Value: ['background-color' > |] | inherit

Initial: see individual properties

Applies to: all elements

Inherited: no

Percentages: allowed on' background-position'

Media: visual

Computed value: see individual properties

The content of the above table is just that the values of the defined background attribute contain those contents, but the order of these values is not specified (although this can be considered the recommended order, and if you do so, the code is more readable).

Thank you for your reading, these are the contents of "how to use the background attribute in CSS". After the study of this article, I believe you have a deeper understanding of how to use the background attribute in CSS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Attributes order code content that is learning selection advantages company single just readability official advice ideas situations articles more knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS Redmi Linux Shulou Technology