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



background-position-y

CSS or Cascading Style Sheets is a language used to describe the presentation of a document written in HTML or XML. It is used to style web pages and make them visually appealing. One of the properties of CSS is the background-position-y property. This property is used to set the vertical position of a background image.

The background-position-y property is a sub-property of the background-position property. It is used to set the vertical position of a background image. The background-position property is used to set the position of a background image both horizontally and vertically. The background-position-y property is used to set the vertical position of a background image only.

The background-position-y property takes a value in pixels, percentages, or keywords. The default value is 0%. A positive value moves the background image down, while a negative value moves it up. If the value is a percentage, it is relative to the height of the element. If the value is a keyword, it can be one of the following:

  • top: The background image is aligned with the top of the element.
  • center: The background image is centered vertically in the element.
  • bottom: The background image is aligned with the bottom of the element.

Here are some examples of using the background-position-y property:

  <style>
    .example1 {
      background-image: url('example.jpg');
      background-position-y: 50%;
    }
    
    .example2 {
      background-image: url('example.jpg');
      background-position-y: -20px;
    }
    
    .example3 {
      background-image: url('example.jpg');
      background-position-y: bottom;
    }
  </style>

  <div class="example1"></div>
  <div class="example2"></div>
  <div class="example3"></div>

In the first example, the background image is centered vertically in the element. In the second example, the background image is moved up by 20 pixels. In the third example, the background image is aligned with the bottom of the element.

The background-position-y property is useful when you want to position a background image vertically in an element. It can be used in combination with the background-position-x property to position a background image both horizontally and vertically.

Overall, the background-position-y property is a useful tool for web developers who want to create visually appealing web pages. It allows them to position background images vertically in an element and create unique designs.

References

Activity