有趣的z-index

实践 :

 

注:firefox

 

示例1:

 

代码:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>有趣的z-index</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
div {
	width:300px;
	height:300px;
	position:relative;
}
#d1 {
	background:yellow;
}
#d2 {
	background:red;
	top:-310px;
}
#d1 p{
	position:relative;
	z-index:2;
}

</style>
</head>
<body>
	<div id="d1">
		<p>元素1</p>
		</div>
		
		<div id="d2">
			<p>元素2</p>
			</div>
	</body>
</html>

 

 

效果:

 

 

 

示例2:


代码:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>有趣的z-index</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
div {
	width:300px;
	height:300px;
	position:relative;
}
#d1 {
	background:yellow;
}
#d2 {
	background:red;
	top:-310px;
}
#d1 p{
	position:relative;
	z-index:2;
}

/*就在这有点东西!*/
#d1 {
	z-index:0;
}
</style>
</head>
<body>
	<div id="d1">
		<p>元素1</p>
		</div>
		
		<div id="d2">
			<p>元素2</p>
			</div>
	</body>
</html>
 


效果:

 

 

 

 

理论:


不懂得话引点权威指南的东西看看:


一旦为一个元素指定了 z-index 值(不是 auto),该元素就会建立自己的局部叠放上下文,这意味着,元素的所有后代相对于该祖先元素都有其自己的叠放顺序。这非常类似于元素建立新包含快的方式。


z-index 默认值 auto 说明:当前叠放上下文中生成框的栈层次与其父框的层次相同。这个框不会建立新的局部叠放上下文,因此如果元素设置为:z-index:auto; 可以将其处理为 z-index:0;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
@charset "utf-8"; *{ margin:0; padding:0; } /* 通配符 所有元素 html中的标签有一些默认央视,清除掉所有的默认间距*/ body{ background: url(../img/bj1.jpg) no-repeat; background-size: cover; } .show{ width:700px; height:400px; position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; animation:rotate 35s linear infinite; /* 3ds属性 */ transform-style:preserve-3d; } @keyframes rotate{ 0%{transform:rotateX(0deg) rotateY(0deg);} 25%{transform:rotateX(5deg) rotateY(90deg);} 50%{transform:rotateX(0deg) rotateY(180deg);} 75%{transform:rotateX(-5deg) rotateY(270deg);} 100%{transform:rotateX(0deg) rotateY(360deg);} } .show img{ width: 100%; height: 100%; position:absolute; border: 50px solid #fff; boeder-radius:30px; top:0; left:0; transition:all 1s; } .show img:nth-child(1) { transform:rotateX(5deg ) rotateY(36deg) translateZ(4000px); } .show img:nth-child(2) { transform: rotateX(5deg )rotateY(72deg) translateZ(3000px); } .show img:nth-child(3) { transform: rotateX(5deg )rotateY(108deg) translateZ(3000px); } .show img:nth-child(4) { transform: rotateX(5deg )rotateY(144deg) translateZ(3000px); } .show img:nth-child(5) { transform:rotateX(5deg ) rotateY(180deg) translateZ(3000px); } .show img:nth-child(6) { transform:rotateX(5deg )rotateY(216deg) translateZ(3000px); } .show img:nth-child(7) { transform: rotateX(5deg )rotateY(252deg) translateZ(3000px); } .show img:nth-child(8) { transform: rotateX(5deg )rotateY(288deg) translateZ(3000px); } .show img:nth-child(9) { transform: rotateX(5deg )rotateY(324deg) translateZ(3000px); } .show img:nth-child(10) { transform:rotateX(5deg ) rotateY(360deg) translateZ(3000px); } .rubbit{ width:250px; height:250px; position:absolute; top:5%; left:5%; } .show img:hover{ position:absolute; top:-700px; width:2200px; height:1400px; background-size: cover; z-index: 1; border: 100px solid #fff; boeder-radius:30px; }修改润色一下
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值