📜  如何在一个声明中设置不同的背景属性?

📅  最后修改于: 2021-09-01 02:55:56             🧑  作者: Mango

我们将在本文中使用速记属性来设置不同的背景属性。

  • 为了减少 CSS 代码的长度,我们可以通过“Shorthand Property”在一行中声明背景属性。
  • 通过这个属性,我们可以在一行中定义背景的不同属性,而不是在多行中使用background-color、background-image等属性。

速记属性:

速记属性允许您使用单个属性指定一组相关的 CSS 属性。它们将相关属性组合成一种简写形式。在大多数情况下,如果您省略可选值,浏览器会设置默认值

句法:

示例 1:

HTML


  

    

  

    

Shorthand Property

       

You can see that background property          are given in a single declaration

     


HTML


  

    Shortand property
    

  

    
        

Shorthand Property

        

The background property is a shorthand property for              specifying all the background properties in one declaration.

        

Here, we took the example of adding multiple              background images and aligned text between them

        

As we have used multiple background images, the              background-color parameter is moved to the end of the list

       
  


输出:

示例 2:具有多个图像的速记属性

HTML



  

    Shortand property
    

  

    
        

Shorthand Property

        

The background property is a shorthand property for              specifying all the background properties in one declaration.

        

Here, we took the example of adding multiple              background images and aligned text between them

        

As we have used multiple background images, the              background-color parameter is moved to the end of the list

       
  

输出: