Curriculum
Course: CSS
Login

Curriculum

CSS

CSS INTRODUCTION

0/1

CSS Selectors

0/1

CSS Comments

0/1

CSS Padding

0/1

CSS Box Model

0/1

CSS Combinators

0/1

CSS Pseudo-classes

0/1

CSS Pseudo-elements

0/1

CSS Dropdowns

0/1

CSS Image Gallery

0/1

CSS Image Sprites

0/1

CSS Counters

0/1

CSS Website Layout

0/1

CSS Specificity

0/1

CSS Math Functions

0/1
Text lesson

Background Shorthand

 

CSS background – Shorthand property

To condense the code, it’s also feasible to consolidate all background properties into a single shorthand property. This is commonly referred to as a shorthand property for backgrounds.

In lieu of composing individual declarations:

body {
  background-color: #ffffff;
  background-image: url(“img_tree.png”);
  background-repeat: no-repeat;
  background-position: right top;
}

You have the option to utilize the shorthand property background.

Example

Utilize the shorthand property to define all background properties within a single declaration.

body {
  background: #ffffff url(“img_tree.png”) no-repeat right top;
}

When employing the shorthand property, adhere to the following order for property values:

  1. background-color
  2. background-image
  3. background-repeat
  4. background-attachment
  5. background-position

Even if one property value is absent, maintain the sequence as specified. Notably, in the examples provided above, the background-attachment property is omitted, as it lacks a value.

All CSS Background Properties

Property

Description

background 

Configures all background properties in a single declaration

background attachment

Determines if a background image stays fixed or scrolls with the page.

background clip

Defines the area where the background will be painted.

background color

Applies a background color to an element.

background image

Applies a background image to an element

background orgin

Specifies where the background image(s) is/are positioned

background position

Sets the starting position of a background image

background repeat

Sets how a background image will be repeated

background size

Specifies the size of the background image(s)