asdjkl 2015-04-30
<DIV id="closeLayer" onClick="closeMe()"><IMG src="jiuye/close.gif" width="15" height="13"></DIV> <div id ="jiuye"><img src="jiuye/jiuye1.jpg" id="jiuyeImage" onclick="javascript:location='http://www.qk12333.com'" style="cursor:hand"/></div> <style type="text/css"> #jiuye{ position:absolute; left:16px; top:129px; width:600px; height:540px; z-index:1; } #closeLayer{ position:absolute; left:580px; top:143px; width:24px; height:19px; z-index:2; } </style> <script src="jiuye/jquery-1.8.0.js" type="text/javascript"></script> <script type="text/javascript"> function closeMe(){ document.getElementById("closeLayer").style.display="none"; document.getElementById("jiuye").style.display="none"; $(window).unbind(); } // 居中 function center() { var obj=$("#jiuye"); var closeObj=$("#closeLayer"); var screenWidth = $(window).width(), screenHeight = $(window).height(); //当前浏览器窗口的 宽高 var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度 var objLeft = (screenWidth - obj.width())/2 ; var objTop = (screenHeight - obj.height())/2 + scrolltop; obj.css({left: objLeft + 'px', top: objTop + 'px','display': 'block'}); var closeObjLeft = (screenWidth + obj.width())/2-closeObj.width()-2 ; var closeObjTop = (screenHeight - obj.height())/2 + scrolltop+12; closeObj.css({left: closeObjLeft + 'px', top: closeObjTop + 'px','display': 'block'}); //浏览器窗口大小改变时 $(window).resize(function() { screenWidth = $(window).width(); screenHeight = $(window).height(); scrolltop = $(document).scrollTop(); objLeft = (screenWidth - obj.width())/2 ; objTop = (screenHeight - obj.height())/2 + scrolltop; obj.css({left: objLeft + 'px', top: objTop + 'px','display': 'block'}); var closeObjLeft = (screenWidth + obj.width())/2-closeObj.width()-2 ; var closeObjTop = (screenHeight - obj.height())/2 + scrolltop+12; closeObj.css({left: closeObjLeft + 'px', top: closeObjTop + 'px','display': 'block'}); }); //浏览器有滚动条时的操作、 $(window).scroll(function() { screenWidth = $(window).width(); screenHeight = $(window).height(); scrolltop = $(document).scrollTop(); objLeft = (screenWidth - obj.width())/2 ; objTop = (screenHeight - obj.height())/2 + scrolltop; obj.css({left: objLeft + 'px', top: objTop + 'px','display': 'block'}); var closeObjLeft = (screenWidth + obj.width())/2-closeObj.width()-2 ; var closeObjTop = (screenHeight - obj.height())/2 + scrolltop+12; closeObj.css({left: closeObjLeft + 'px', top: closeObjTop + 'px','display': 'block'}); }); } center(); $('#closeLayer').show(300).delay(3000).fadeOut("slow"); $('#jiuye').show(300).delay(3000).fadeOut("slow",function(){ //隐藏时把元素删除 $(window).unbind(); }); </script>
<divid="cnbruce">margin:0auto看看内容居中否</div>. 然后,单个div的CSS居中,非要扯上<body>?其实原理都知道,就是因为用这个“懒人”的HTML调试框,懒得
<div id="wrap"> 在所有浏览器中都有效的方法: <pre> 在所有浏览器中都有效的方法: 在所有浏览器中都有效的方法: 在所有浏览器中都有效的方法:. </div>太烂了这种方案!这样定
doctype html>如果不添加这段,ie没有找到合适的解析标准就会以默认的ie5.5的方式来解析页面,在ie5.5里边,css写margin:0 auto是不管用的,盒模型的宽高计算也是错误的。