HTML DOM position ÊôÐÔ
¶¨ÒåºÍÓ÷¨
position ÊôÐÔ°ÑÔªËØ·ÅÖõ½Ò»¸ö¾²Ì¬µÄ¡¢Ïà¶ÔµÄ¡¢¾ø¶ÔµÄ¡¢»ò¹Ì¶¨µÄλÖÃÖС£
Óï·¨£º
Object.style.position=static|relative|absolute|fixed
¿ÉÄܵÄÖµ
Öµ | ÃèÊö |
---|---|
static | ĬÈÏ¡£Î»ÖÃÉèÖÃΪ static µÄÔªËØ£¬ËüʼÖջᴦÓÚÒ³ÃæÁ÷¸øÓèµÄλÖã¨static ÔªËØ»áºöÂÔÈκΠtop¡¢bottom¡¢left »ò right ÉùÃ÷£©¡£ |
relative | λÖñ»ÉèÖÃΪ relative µÄÔªËØ£¬¿É½«ÆäÒÆÖÁÏà¶ÔÓÚÆäÕý³£Î»Öõĵط½£¬Òò´Ë "left:20" »á½«ÔªËØÒÆÖÁÔªËØÕý³£Î»ÖÃ×ó±ß 20 ¸öÏñËØµÄλÖᣠ|
absolute | λÖÃÉèÖÃΪ absolute µÄÔªËØ£¬¿É¶¨Î»ÓÚÏà¶ÔÓÚ°üº¬ËüµÄÔªËØµÄÖ¸¶¨×ø±ê¡£´ËÔªËØµÄλÖÿÉͨ¹ý "left"¡¢"top"¡¢"right" ÒÔ¼° "bottom" ÊôÐÔÀ´¹æ¶¨¡£ |
fixed | λÖñ»ÉèÖÃΪ fixed µÄÔªËØ£¬¿É¶¨Î»ÓÚÏà¶ÔÓÚä¯ÀÀÆ÷´°¿ÚµÄÖ¸¶¨×ø±ê¡£´ËÔªËØµÄλÖÿÉͨ¹ý "left"¡¢"top"¡¢"right" ÒÔ¼°"bottom" ÊôÐÔÀ´¹æ¶¨¡£²»ÂÛ´°¿Ú¹ö¶¯Óë·ñ£¬ÔªËض¼»áÁôÔÚÄǸöλÖ᣹¤×÷ÓÚ IE7£¨strict ģʽ£©¡£ |
ʵÀý
±¾Àý°ÑÔªËØÎ»ÖÃÓÉÏà¶Ô¸ÄΪ¾ø¶Ô£º
<html>
<head>
<style type="text/css">
input
{
position:relative;
}
</style>
<script type="text/javascript">
function setPositionAbsolute()
{
document.getElementById("b1").style.position="absolute";
document.getElementById("b1").style.top="10px";
}
</script>
</head>
<body>
<p>This is an example paragraph</p>
<p>This is an example paragraph</p>
<input type="button" id="b1" onclick="setPositionAbsolute()"
value="Set button position to be absolute" />
</body>
</html>