The background-position-x property
The background-position-x
property
specifies a horizontal position of an element’s
background image.
The property can take the following values:
left
, center
, right
, and
you can also specify the background position
in percentages or pixels.
Syntax
selector {
background-position-x: value;
}
Example
Let's position the background on the left horizontally:
<div id="elem"></div>
#elem {
background-position-x: left;
background-image: url("bg.png");
background-repeat: no-repeat;
width: 400px;
height: 300px;
border: 1px solid black;
}
:
Example
Now let's move the background to the right:
<div id="elem"></div>
#elem {
background-position-x: right;
background-image: url("bg.png");
background-repeat: no-repeat;
width: 400px;
height: 300px;
border: 1px solid black;
}
:
Example
Let's place the background image in the center:
<div id="elem"></div>
#elem {
background-position-x: center;
background-image: url("bg.png");
background-repeat: no-repeat;
width: 400px;
height: 300px;
border: 1px solid black;
}
:
Example
Now let’s set the position for the background as a percentage:
<div id="elem"></div>
#elem {
background-position-x: 20%;
background-image: url("bg.png");
background-repeat: no-repeat;
width: 400px;
height: 300px;
border: 1px solid black;
}
:
See also
-
the
background
property
that is a shorthand property for a background -
the
background-position-y
property
that specifies a background position vertically