Sets or retrieves the position of the object relative to the left edge of the next positioned object in the document hierarchy. dhtml语法 HTML |
{ left : sPosition }
|
---|
Scripting | object.style.left [ = sPosition ] |
---|
DHTML可能的值 sPosition | Variant that
specifies or receives one of the following values.auto | Default. Default position, according to the regular HTML layout of the page. | length | Floating-point number, followed by an absolute units designator (cm, mm, in, pt, pc, or px) or a relative units designator (em or ex). For more information about the supported length units, see css length units reference. | percentage | Integer, followed by a percent sign (%). The value is a percentage of the width of the parent object. |
|
The property is read/write
for all objects except the following, for which it is read-only:
currentStyle.
The property has a default value of
auto. The Cascading Style Sheets (CSS) attribute is
not inherited.
Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see about dynamic properties.
remarks you should use the left attribute only when the position attribute is set; otherwise, the value of the left attribute is ignored. because the value of the left property is a string, you cannot use the property in script to calculate the position of the object in the document; instead, you should use the pixelleft property or the posleft property. for more information about how to access the dimension and location of objects on the page through the dynamic html(动态html,即dhtml)燿ocument object model (dom), see measuring element dimension and location.
Examples
The following examples use the left attribute and the left property to change the position of the object.
This example uses an inline style sheet to set the position of an image 100 pixels to the right of the parent object's left edge. <DIV STYLE="position:absolute;left:100px">
<IMG SRC="cone.jpg"></DIV> This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.
This example uses inline scripting to change the position of two images when an onclick event occurs. <button onclick="cone.style.left='100px'; sphere.style.left='200px'">
. . .</BUTTON> This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample. 是否符合公共标准
This property is defined in
Cascading Style Sheets (CSS), Level 2 (CSS2) .
Applies To |
A,
ADDRESS,
APPLET,
B,
BIG,
BLOCKQUOTE,
BUTTON,
CENTER,
CITE,
CODE,
currentStyle,
CUSTOM,
DD,
defaults,
DFN,
DIR,
DIV,
DL,
DT,
EM,
EMBED,
FIELDSET,
FONT,
FORM,
hn,
HR,
I,
IFRAME,
IMG,
INPUT type=button,
INPUT type=checkbox,
INPUT type=file,
INPUT type=image,
INPUT type=password,
INPUT type=radio,
INPUT type=reset,
INPUT type=submit,
INPUT type=text,
ISINDEX,
KBD,
LABEL,
LEGEND,
LI,
LISTING,
MARQUEE,
MENU,
OBJECT,
OL,
P,
PRE,
runtimeStyle,
S,
SAMP,
SELECT,
SMALL,
SPAN,
STRIKE,
STRONG,
style,
SUB,
SUP,
TABLE,
TEXTAREA,
TT,
U,
UL,
VAR,
XMP | |
|