You are here: Reference > JavaScript > client-side > style handling > properties > backgroundPositionY
Specifies or returns the vertical-coordinate of the backgroundImage relative to the upper-left corner of the container object.
This property is not supported by all browsers, so use backgroundPosition property instead wherever you can.
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: background-position-y |
The type of this property is string.
Background is aligned to the bottom. | |||||||
Background is vertically centered. | |||||||
The vertical position of the background in length units. For the supported length units, see the length page. | |||||||
The vertical position is the specified percentage of the height of the object. | |||||||
Background is aligned to the top. |
Default: 0%.
This example illustrates the use of the background-position-y property:
|
||||
<head> <style> .example { background-image: url("bg.jpg"); background-repeat: no-repeat; width: 200px; height: 200px; border:1px solid #CCCCCC; background-position-x: center; } .top { background-position-y: top; } .bottom { background-position-y: bottom; } </style> </head> <body> <div class="example top" style=" float:right;"> The image is at the top of this division. </div> <div class="example bottom"> The image is at the bottom of this division. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
This example illustrates the use of the backgroundPositionY property in JavaScript:
|
||||
<head> <style> .example { background-image: url("bg.jpg"); background-repeat: no-repeat; background-position: center top; width: 200px; height: 200px; border:1px solid #CCCCCC; } </style> <script type="text/javascript"> function ChangeBgPos () { var selects = document.getElementsByTagName ("select"); // Returns the selected elements var selectStates = []; for (var i=0; i < selects.length; i++) { var whichSelected = selects[i].selectedIndex; selectStates.push (selects[i].options[whichSelected].text); } var div = document.getElementById ("myDiv"); if ('backgroundPositionX' in div.style) { div.style.backgroundPositionX = selectStates[0]; div.style.backgroundPositionY = selectStates[1]; } else { div.style.backgroundPosition = (selectStates[0] + " " + selectStates[1]); } } </script> </head> <body> <div class="example" id="myDiv"> Change the values of the horizontal and vertical image positions. </div> <br /> <select onchange="ChangeBgPos ();" size="3"> <option selected="selected" />center <option />left <option />right </select> <select onchange="ChangeBgPos ();" size="3"> <option />bottom <option />center <option selected="selected" />top </select> </body> |
||||
|
||||
Did you find this example helpful?
|
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, b, bdo, big, blockquote, body, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, pre, q, rt, ruby, s, samp, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
background
backgroundAttachment
backgroundColor
backgroundImage
backgroundPosition
backgroundPositionX
backgroundRepeat
backgroundAttachment
backgroundColor
backgroundImage
backgroundPosition
backgroundPositionX
backgroundRepeat
User Contributed Comments