CSS CSS Tutorial CSS Advanced CSS Responsive Web Design(RWD) CSS Grid CSS Properties Sass Tutorial Sass Functions



background-origin

CSS (Cascading Style Sheets) is a style sheet language used for describing the presentation of a document written in HTML (Hypertext Markup Language). CSS properties are used to style the HTML elements and make them visually appealing. One such property is background-origin.

Introduction of Background-Origin

Background-origin is a CSS property that specifies the origin position of the background image. It determines where the background image starts from. The background image can be positioned relative to the content box, padding box, or border box of an element. The default value of background-origin is padding-box.

Brief Explanation about Background-Origin

The background-origin property is used to set the origin position of the background image. It determines the starting point of the background image. The background image can be positioned relative to the content box, padding box, or border box of an element. The three possible values of background-origin are:

  • content-box: The background image starts from the upper-left corner of the content box of an element.
  • padding-box: The background image starts from the upper-left corner of the padding box of an element.
  • border-box: The background image starts from the upper-left corner of the border box of an element.

The following code examples demonstrate the use of background-origin property:

Example 1: Using background-origin with content-box value

  
    .example {
      background-image: url('example.jpg');
      background-origin: content-box;
    }
  

In this example, the background image will start from the upper-left corner of the content box of the element with class "example".

Example 2: Using background-origin with padding-box value

  
    .example {
      background-image: url('example.jpg');
      background-origin: padding-box;
    }
  

In this example, the background image will start from the upper-left corner of the padding box of the element with class "example".

Example 3: Using background-origin with border-box value

  
    .example {
      background-image: url('example.jpg');
      background-origin: border-box;
    }
  

In this example, the background image will start from the upper-left corner of the border box of the element with class "example".

Conclusion

The background-origin property is used to set the origin position of the background image. It determines the starting point of the background image. The background image can be positioned relative to the content box, padding box, or border box of an element. The three possible values of background-origin are content-box, padding-box, and border-box.

References

Activity