backgroundPosition Property
Returns or sets a String that represents the position of the background image for an object, such as a document or table. If the backgroundImage property is not set, this property will do nothing. The backgroundPosition property corresponds to the background-position property for a cascading style sheet.
expression.backgroundPosition
expression Required. An expression that returns one of the objects in the Applies To list.
Remarks
The String value of the backgroundPosition property can be one or more of the following:
length |
Sets the horizontal or vertical position of the background image to an exact location. Floating-point number, followed by an absolute units designator (cm , mm , in , pt , pc , or px ) or a relative units designator (em or ex ). Positions the left and top edges of the background image at a specific spot on a page. The following code sets the backgroundPosition property to 50px and 10px, which positions the left edge of the the background image to 50 pixels from the left edge of the page and positions the top edge of the background image 10 pixels from the top edge of the page.
|
||||||
percentage |
Integer, followed by a percent sign (%). The value is a percentage of the width or height of the object. For example, the following code sets the left edge of the background image to 10 percent of the width of the page and the top edge of the background image to 25 percent of the height of the page.
|
||||||
vAlignment |
Vertical alignment value consisting of one of the following:
If no setting is specified for If Use the backgroundPositionY property to set the vertical position of a background image. |
||||||
hAlignment |
Horizontal alignment value consisting of one of the following:
If no setting is specified for If Use the backgroundPositionX property to set the vertical position of a background image. |
Note If one measurement is provided for length
or percentage
, then the horizontal position is set to the measurement provided; if two measurements are provided, then the horizontal and vertical positions are set to the measurements provided. The horizontal position is set equal to the first measurement; the vertical position is set equal to the second measurement. For example, the following code sets the horizontal position of the background image to 15 percent of the page width and the vertical position of the background image to 25 pixels from the top edge of the page.
ActiveDocument.body.Style.backgroundPosition = "15% 25px"
When the backgroundRepeat property is set to repeat (the default setting), the left and top edges of the image start at the specified position (or the default setting if no setting is specified) and then repeat around the image in all directions. For example, if you set the backgroundPosition property for a background image to 15px 50px
, the left edge of the background image will be 15 pixels from the left edge of the browser window and the top edge will be 50 pixels from the top edge of the browser window. However, with the backgroundRepeat property set to repeat, the right and bottom edges of the image will display above and to the left of the starting position as well as to the right and below of the starting position.
You can use the background property to set the backgroundAttachment, backgroundColor, backgroundImage, backgroundPosition, and backgroundRepeat properties. The following code shows what the example below would look like if you were using the background property to set each of these properties.
ActiveDocument.body.Style.Background = "fixed " & _
"url(graphics/chelan.jpg) blue top center no-repeat"
Example
The following example sets the background color and image settings for the active document.
With ActiveDocument.body.Style
.backgroundAttachment = "fixed"
.backgroundImage = "graphics/chelan.jpg"
.backgroundColor = "blue"
.backgroundPosition = "top center"
.backgroundRepeat = "no-repeat"
End With