z-index与css多背景图

 在这个周的实习中需要实现如下一个功能



即左上角的排名数字是可以随便填的,左上角的红色区域,中间的点击图标是可以通过css可以修改,这个需要通过z-index来设置各个图层的深度,具体代码如下,大家可以参考

 <html>
 <head>
  <style type="text/css">
  .wrap{
  width: 240px;
  height: 240px;
margin: 0px auto;
  background-color: #ccc;
overflow: hidden;
  }
  .top_left{
  z-index: 100;
  width: 48px;
  height: 48px;
  background: url(paihang.png);
  top:-60px;
  left:0px;
  position: relative;
  }
  .center{
  z-index: 100;
  width: 48px;
  height: 48px;
  background: url(dianji.png);
  top:-20px;
  left: 90px;
  position: relative;
  }
  .paiming{
  z-index: 101;
  top: -15px;
  left:10px;
  position: relative;
  }
  img{
  width:240px;
height: 240px;
top: -155px;
left:0px;
position: relative;
  }
  </style>
 </head>
 <body>
  <div class="wrap">
  <div class="paiming"><h3>1</h3></div>
  <div class="top_left"></div>
  <div class="center"></div>
  <img src="1.jpg" alt="">
  </div>
 </body>
大家可以发现其中,红色区域和点击图标是分开设置,但其实完全可以通过一个图层来实现,不过这就需要使用多背景图了。关键代码:
.box{
  z-index: 100;
  width: 240px;
  height: 240px;
  top: -58px;
  position: relative;
  background: url(paihang.png) no-repeat left top,
  url(dianji.png) no-repeat center center;
  }

 <html>
 <head>
  <style type="text/css">
  .wrap{
  width: 240px;
  height: 240px;
margin: 0px auto;
  background-color: #ccc;
overflow: hidden;
  }
  .box{
  z-index: 100;
  width: 240px;
  height: 240px;
  top: -58px;
  position: relative;
  background: url(paihang.png) no-repeat left top,
  url(dianji.png) no-repeat center center;
  }
  .paiming{
  z-index: 101;
  top: -15px;
  left:10px;
  position: relative;
  }
  img{
  width:240px;
height: 240px;
top: -301px;
left:0px;
position: relative;
  }
  </style>
 </head>
 <body>
  <div class="wrap">
  <div class="paiming"><h3>1</h3></div>
  <div class="box"></div>
  <img src="1.jpg" alt="">
  </div>
 </body>


具体源文件在:http://pan.baidu.com/share/link?shareid=2881317635&uk=1998297189

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值