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 xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title> 
<style type="text/css"  >
 .relative{clear:both;width:100%;}
 div{float:left;width:200px ; height:100px ;}
 .div1{ background:#999; position:relative;left:100px;}
 .div2{background:#06F}
  .absolute{clear:both;width:100%;position:relative;left:20px;}
 .div3{ background:#999;position:absolute;right:0px;}
 .div4{background:#06F}
 
  .fixed{clear:both;width:100%;position: fixed;left:400px; z-index:1;}
 .div5{ background:#990;}
</style>

</head>

<body>

<div class="relative">
	<div class="div1">div1</div>
	<div class="div2">div2</div>
</div>

<div class="absolute">
	<div class="div3">div3</div>
	<div class="div4">div4</div>
</div>
<div class="fixed">
	<div class="div5">div5</div>
	<div class="div6">div6</div>
</div>

</body>
</html>






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值