简体   繁体   English

Z-index属性CSS

[英]Z-index attribute CSS

I'm having a problem with the z-index. 我的z-index有问题。

I want to set a <a> that on when is hover it changes the class of the <a> and makes it be over something. 我想设置一个<a> ,它在何时悬停时会更改<a>的类,并使它超出某个范围。

So I have set the <a> 's z-index=-1 and the other thing's z-index=1 and when you hover it changes the <a> 's class and in the class the z-index=2 so it suppose to be over the other thing, but it doesn't. 所以我已经设置了<a>z-index=-1和其他东西的z-index=1 ,当您将其悬停时,它会更改<a>的类,并且在类中将z-index=2为应该超越另一件事,但事实并非如此。 I tried to set that on hover instead of changing the <a> 's z-index I have changed the other thing z-index to -2 and yet it didn't work. 我试图设置上悬停,而不是改变<a>z-index我已经改变了另一件事z-index-2 ,但没有奏效。

I don't want to use the display=none and then to change the display because when the picture is not over the other thing you can still see some of it. 我不想使用display=none然后更改显示,因为当图片没有覆盖其他东西时,您仍然可以看到其中的一部分。

What is the problem? 问题是什么? How do I fix it? 我如何解决它?

Thx for the help :D 谢谢你的帮助:D

EDIT: here is the code: 编辑:这是代码:

Code behind: 后面的代码:

protected void show_view1(object sender, EventArgs e)
    {
        L1.Attributes.Add("class", "active");
    }

html: HTML:

<div id='settingNev' >
<ul >
  <li id="L1"  runat="server"><a id="A1" onserverclick="show_view1" runat="server"><span>Personal</span></a></li>
</ul>
</div>

the table i want it tio be over of when the mouse is hover the <a> : 鼠标悬停<a>时我要结束的表:

<table style="border:1px solid black; padding:0px 0px 0px 0px; margin: 0px 0; position:relative;  z-index:1;" cellspacing="20">

css: CSS:

    #settingNev {
      float: left;
      width: 100%;
      background: TRANSPERANT;
      font-size: 93%;
      line-height: normal;
    }
    #settingNev ul {
      margin: 0;
      padding: 10px 10px 0 50px;
      list-style: none;
    }
    #settingNev li {
      display: inline;
      margin: 0;
      padding: 0;
    }
//....here is the z-index set................
    #settingNev a {
      float: left;
      margin:0 3px 0 3px;
      padding: 0 0 0 4px;
      text-decoration: none;
      z-index:-1;
      border:1px solid black;
      border-radius: 6px 6px 0px 0px; 
//.............................................
    }
    #settingNev a span {
      float: left;
      display: block;
      padding: 5px 15px 4px 6px;
      color: #666;
    }
    #settingNev a span {
      float: none;
    }
    #settingNev .active a span,
    #settingNev a:hover span {
      color: #FFFFFF;
    }
    #settingNev .active a,
    #cssmenu a:hover {
      background-position: 0 -42px;
      border-bottom:0px solid black;
    }
//....here is the z-index set................
    #settingNev .active a span,
    #settingNev a:hover span {
      background-position: 100% -42px;
      z-index:2;
    }

To make z-index works you must have one of this position (s) to you style element 要使z-index有效,您的样式元素必须具有以下position之一

  • absolute 绝对
  • relative 相对的
  • fixed 固定

any other position make z-index to not work. 任何其他position会使z-index不起作用。

In jQuery, 在jQuery中,

$("button").click(function(){
    $("the element").css("z-index","2");
};

you did something like this? 你做了这样的事吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM