从下往上走的话,就不要用top属性,改用bottom,这样写法是:(i-10)*60+'px'
如果一定要用top,就这样:(19-i)*60+'px'
<style>div{width:50px height:50px background-color:red position:absolute font-size:30px text-align:center}
</style>
<script>
window.onload=function(){
for(var i=0i<20i++){
var div=document.createElement("div")
div.innerHTML=i
if(i<10){
div.style.left=i*60+'px'
div.style.top=i*60+'px'
}else{
div.style.right=(19-i)*60+'px'
div.style.top=(19-i)*60+'px'
}
document.body.appendChild(div)
}
}
</script>
绝对相对于父元素的位置。position:relative
相对于父元素的相对位置。与absolute的区别是,relative与元素之间不可能交叉重叠。
position:static
静态位置。这个是个默认值。使用了这个属性,它的作用就与table差不多了。不能用left,top来定位
position:fixed 相对于浏览器的位置。无论,网页的滚动条如何滚动,它都会纹丝不动。