left style property
Specifies or returns the left coordinate of a positioned element.
A positioned element is an element whose position property is set to relative, absolute or fixed.
The value of the left property specifies the left position of the element including
the padding, scrollbar, border and the margin.
The type of the left property is string. You can set or retrieve the value of the left property as an integer with the pixelLeft property. It contains the value in pixels.
If you want to get or set the left property as a floating-point number that specifies the value in the current unit type of the left property, use the posLeft property.
The properties mentioned above can be used to access style settings.
If you need the left position of a rendered element, you can use the clientLeft, offsetLeft and scrollLeft properties and the getBoundingClientRect method.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: left |
Possible values:
The type of this property is string.
One of the following values:
Default. The left coordinate of the object is in accordance with the default layout of the page. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
The left coordinate of the element in length units. For the supported length units, see the length page. | |||||||
The left coordinate is the specified percentage of the width of the parent object. |
Default: auto.
Example HTML code 1:
This example illustrates the use of the left property:
|
||||
<head> <style> .example { position: relative; left: -50px; top: -20px; } </style> </head> <body> <img src="bg.jpg"> <span class="example">over image</span> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the left property in JavaScript:
|
||||
<head> <style> #myDiv { position: absolute; left: 100px; top: 60px; width: 200px; height: 50px; background-color: #c00000; } </style> <script type="text/javascript"> function ChangeLeft () { var div = document.getElementById ("myDiv"); var input = document.getElementById ("myInput"); div.style.left = input.value + "px"; } </script> </head> <body> <div id="myDiv"> An absolute positioned division </div> <input id="myInput" type="text" value="100" /> <button onclick="ChangeLeft ();">Change the left position!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, applet, b, bdo, big, blink, blockquote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, 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, object, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, textarea, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments