How to Set Background Position

After adding a background image and stopping it from repeating, we are able to further control how it looks within the background of the tag by improving its position.

We’ll use the background-position property to do this.

The selector takes in two values. The first one is for the horizontal position, or x-direction (how far across the tag). The second one is for the vertical position, or y-direction (how far down the tag).

The values can be units, like a pair of pixels:

section {
    background-position: 20px 30px;
        }

This will move the image 20px across and 30px down the containing tag.

Instead of pixels we can use a set of keywords like right, left, top, down, or center to place the image at the right, left, top, down, or center of the tag.

section {
    background-position: right center;
        }

This places the image at the right hand side of the center of the tag.

Leave a comment

Your email address will not be published. Required fields are marked *