当前位置:编程学习 > C#/ASP.NET >>

div层的位置问题

如何控制div的位置啊 --------------------编程问答-------------------- abstract position:
related  position: --------------------编程问答-------------------- 不知LZ想怎么个控制法,用CSS就可以了。若要点其他效果,再用点JS --------------------编程问答-------------------- 是不是在一个页面里面有多个div?让它一次选一个?
属性中加style:disply=none,用这个。可以让每个显示的时候,都在最上面。 --------------------编程问答-------------------- 如果你想通过javascript控制div位置,原理是:
通过间接的方法,向上找父级,一直找到最底层,
取得位置,然后以此位置为基础,确定你需要的div的位置。
一会我写个简洁代码。 --------------------编程问答--------------------
<script type="text/javascript">


function $(o){return typeof(o)=="string"?document.getElementById(o):o}
function ae(o,e,f){if(!e){f=o;o=window;e="load"}try{o.attachEvent("on"+e,f)}catch(s){o.addEventListener(e,f,false)}}
function fe(e){e=e||event;return{x:e.clientX,y:e.clientY}}
function fo(o){l=o.offsetLeft;t=o.offsetTop;w=o.offsetWidth;h=o.offsetHeight;while(o=o.offsetParent){l+=o.offsetLeft;t+=o.offsetTop}return {x:l,y:t,w:w,h:h}}
function json(s){try{return eval("("+s+")")}catch(e){return null}}
function debug(o){a=[];for(k in o)a.push(k+":"+o[k]);alert(a.join("\n"))}
function write(s){$("msg").innerHTML=s}


function f(o){
  var p=fo(o);
  debug(p);
  o.style.left='333px';
  

}
</script>
<br>
<br>
<br>
<br>
<div>click</div>
<div id="div1" onclick="f(this)" style="position:absolute;width:300px;height:200px;background:#eef;">div1</div>
--------------------编程问答-------------------- <div style="position:absolute;left:100px;top:100px;"> --------------------编程问答--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
    <script type="text/javascript">
    //寻找位置函数
    function fp(o){l=o.offsetLeft;t=o.offsetTop;w=o.offsetWidth;h=o.offsetHeight;while(o=o.offsetParent){l+=o.offsetLeft;t+=o.offsetTop}return {x:l,y:t,w:w,h:h}}
    function f(o){
        var p = fp(o);
        var msg = "距左:"+p.x+"  距顶:"+p.y+"  宽:"+p.w+"  高:"+p.h;
        alert(msg);
    }
    function c(o){
        var p = document.getElementById(o);
        p.style.left = '100px';
        p.style.top = '100px';
    }
    </script>
</head>
<body>
<div id="div1" onclick="f(this)" style="position:absolute;width:300px;height:200px;background:#eef;">点击查看位置信息</div>
<div id="div2" onclick="c('div1')" style="position:absolute; left:300px;">点击改变位置</div>
</body>
</html>
--------------------编程问答-------------------- 运行一下,看看,今天我正好研究这个,呵呵。难道你只是提问css?学学js怎样控制css吧。 --------------------编程问答-------------------- <div id="MyFormLayer" style="display: none; z-index: 9999; left: 76px; width: 750px;
            position: absolute; top: 80px; height: 500px; background-color: BlueViolet">
        </div>
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,