z-index for button over jquery slider

时光总嘲笑我的痴心妄想 提交于 2019-12-11 13:18:28

问题


I have a full screen jquery slider and I need to put two buttons on it (to increase and decrease the speed of the slider). I tried with z-index in the css file but it's not working.

div#lyr1 {
     position:relative;
    z-index:1;
    }
.ui.button {
  ...
  position:relative;
  z-index:2;}

And here's the html code

<div id="wn">
   <div id="lyr1">
      <div id="inner1"> 
          <img src="images/1-2.png" width="2000"height="1100" alt="" />
          <img id="rpt1" src="images/1-2.png" width="2000" height="1100" alt="" />
      </div> 
     <div class="ui button">Follow</div>
   </div>
</div>

How can I do it ?

Thank you.


回答1:


The way the code is written, the z-index properties aren't really doing anything. Since ui button is a child of lyr1, they don't share the same stacking context.

You'll need to move ui button to be a sibling of lyr1, and then you should see some results.

Like so:

<div id="wn">
   <div id="lyr1">
      <div id="inner1"> 
          <img src="images/1-2.png" width="2000"height="1100" alt="" />
          <img id="rpt1" src="images/1-2.png" width="2000" height="1100" alt="" />
      </div> 
   </div>
   <div class="ui button">Follow</div>
</div>



回答2:


When I tested your original code, the button was on top of lyr1 without extra css. There must be something else in the slider that is effecting the layer stack.

<html>
<body>
<style>
div#lyr1 {
  background:#000;
}
.ui.button {
  background:#111;
  color:#ccc;
}
</style>
<div id="wn">
   <div id="lyr1">
      <div id="inner1"> 
          <img src="images/1-2.png" width="200"height="200" alt="" />
          <img id="rpt1" src="images/1-2.png" width="200" height="200" alt="" />
      </div> 
      <div class="ui button">Follow</div>
   </div>
</div>
</body>
</html>


来源:https://stackoverflow.com/questions/28721971/z-index-for-button-over-jquery-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!