CSS:得到一个div重叠的按钮,z-index不起作用

时间:2014-09-10 12:06:29

标签: html css z-index

Fiddle Example

有人能弄明白如何让按钮重叠flyout-content,以便隐藏按钮的右边框吗?我想得到这个效果:

enter image description here

我尝试更改内容和按钮的z-index,但它无法正常工作。

HTML

<div class='flyout'>
  <button class="flyout-toggle">Click</button>
  <div class="flyout-content"></div>
</div>

CSS

.flyout-toggle {
    position: absolute;
    transform: rotate(90deg);
    top: 50%;
    left: -50px;
    z-index: 998;
    width: 85px;
    height: 35px;
    font-size: 13px;
    background: #92C7B8;
    border: solid #fff 1px;
}
.flyout-content {
    z-index:997
}
.flyout {
    position: fixed;
    z-index: 999;
    top: 0;
    right: 0;
    width: 15%;
    height: 100%;
    border-left: solid #fff 1px;
    background: #92C7B8;
    -webkit-box-shadow: 0px -5px 15px 0px #bfbfbf;
    box-shadow: 0px -5px 15px 0px #bfbfbf;
    transition: all .3s ease-in-out;
}

4 个答案:

答案 0 :(得分:5)

只需添加此border:none;

即可
.flyout-toggle {
    background: none repeat scroll 0 0 #92c7b8;
    border: medium none;
    font-size: 13px;
    height: 35px;
    left: -50px;
    position: absolute;
    top: 50%;
    transform: rotate(90deg);
    width: 85px;
    z-index: 998;
}

但是如果你需要一个边框,你可以将它添加到你需要一个边框顶部边框 - 左边框 - 右边;像这样DEMO

答案 1 :(得分:2)

您可以使用border-top: noneoutline: none

.flyout-toggle {
    position: absolute;
    transform: rotate(90deg);
    top: 50%;
    left: -60px;
    z-index: 998;
    width: 85px;
    height: 35px;
    font-size: 13px;
    background: #92C7B8;
    border: solid #fff 1px;
    border-top: none;
    outline: none;
}

fiddle

答案 2 :(得分:0)

z-index元素必须位于同一级别。在您的情况下,flyout具有最大的z-index,但他是flyout-toggle的父级,其中较小的一级。{/ p>

试试这样:

HTML:

<div class="parent">
    <button class="flyout-toggle">Click</button>
    <div class="flyout"></div>
</div>

CSS:

.parent{
    position: fixed;
    top: 0;
    bottom:0;
    right: 0;
    height:100%;
    width: 15%;
}

现在我将position:fixed个样式添加到parent,而不是其子flyout

Check the full fiddle,您会注意到按钮的右侧无法点击,因为flyout已超过它。

答案 3 :(得分:-1)

在.flyout-toggle change

z-index: 998; to z-index: -1. 

check this jsfiddle