Css控制层在中间以及右下角显示(附…

这篇博客介绍了如何使用CSS和JavaScript来实现网页元素在屏幕中间以及右下角显示。通过调整CSS的position属性和利用JavaScript动态计算窗口大小,可以确保元素始终定位正确。同时,文章还提供了不同定位方式的示例代码,包括居中、右下角等,并提到了在IE6中的兼容性处理。
摘要由CSDN通过智能技术生成

1.css

<style type="text/css">
<!--
#cao {
 background-color: #3366FF;
 height: 200px;
 width: 200px;
 position: fixed;
 top:50%;
 left:50%;
 margin-left:-100px;
 margin-top:-100px;
}
body,td,th {
 font-size: 12px;
 text-align: center;
}
-->
</style>
<body>
<div id="cao">CAO888</div>
</body>
2.js:

<style type="text/css">
<!--
#cao {
 background-color: #3366FF;
 height: 200px;
 width: 200px;
 position: fixed;
}
body,td,th {
 font-size: 12px;
 text-align: center;
}
-->
</style>
<script language=javascript>
function changeIt() {
var myobj=document.getElementByIdx("cao");
var bodyhh=document.body.clientHeight;
var bodyww=document.body.clientWidth;
var objhh=myobj.clientHeight;
var objww=myobj.clientWidth;
myobj.style.top=(bodyhh-objhh)/2;
myobj.style.left=(bodyww-objww)/2;
}
</script>
<body onresize="changeIt()" onload="changeIt()">
<div id="cao">CAO888</div>
</body>
3.css右下角:

<style type="text/css">
       
    
     #div2{bottom:3px; right:0px;position:fixed;}

</style>

 

   <form id="form1" runat="server">
    <div id="div1" onclick="this.style.display='none';document.getElementByIdx('div2').style.display='';" > </div>
<div id="div2" onclick="this.style.display='none';document.getElementByIdx('div1').style.display='';" style="background:#fff url(http://www.wholesale-retailer.com/zzz_js/old/bbb.gif) no-repeat;cursor:pointer;width:20px;height:200px; display:none;"> </div>
太强大了~

 

记下网址:http://www.sosuo8.com/article/show.asp?id=1578

 

完美示例:

<%@ Page Language="C#" CodeFile="DivTest.aspx.cs" Inherits="DivTest" %>

<!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 runat="server">
    <title>无标题页</title>
   
    <style type="text/css">
       
    
     #div2{b

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值