What values does background-position accept?

079

The background-position property in CSS accepts several types of values to specify the position of a background image. Here are the main options:

  1. Keywords:

    • top, bottom, left, right, center
    • Example: background-position: top left;
  2. Length values:

    • You can use units like px, em, %, etc.
    • Example: background-position: 50px 100px;
  3. Percentage values:

    • Values can be specified as percentages of the element's dimensions.
    • Example: background-position: 50% 50%; (centers the image)
  4. Multiple values:

    • You can specify both horizontal and vertical positions.
    • Example: background-position: right 20px bottom 10px;

Example:

.element {
  background-image: url('image.jpg');
  background-position: center top; /* Centers horizontally, aligns to the top */
}

Feel free to ask if you need more details or examples!

0 Comments

no data
Be the first to share your comment!