添加不透明背景而不重叠其他元素

时间:2016-02-17 17:19:56

标签: jquery html css

我正在尝试为菜单设置不透明的背景而不使我的列表和图标关闭按钮也不透明。我尝试使用z-index但它没有用。

背景div也会破坏图标关闭按钮上的链接,因此即使背景div位于图标下方,我也无法关闭菜单。

我的小提琴:

Fiddle Here

我的HTML代码:

<div class="menu">
  <!-- Menu icon -->
  <div class="icon-close">
    <i class="fa fa-remove fa-3x"></i>
  </div>
  <ul>
    <li>Home</li>
    <li>About Me</li>
    <li>Contact Me</li>
    <li>Gallery</li>
  </ul>
  <div id="background"></div>
</div>
<div id="jumbotron">
  <div id="icon-move">
    <div class="menu-icon">
      <i class="fa fa-bars fa-3x"></i>
    </div>
  </div>
</div>

我的CSS代码:

#jumbotron {
    width: 100%;
    height: 750px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-image: url("images/logogreybg.png");
}

.menu-icon {
    color: #fff;
    cursor: pointer;
    font-family: 'Open Sans', sans-serif;
    font-size: 16px;
    padding-bottom: 25px;
    padding-left: 25px;
    padding-top: 25px;
    text-decoration: none;
    text-transform: uppercase;
    z-index:2;
}

.menu-icon i {
    margin-right: 5px;
    color: #3C5F7C;
    z-index:2;
}

.icon-close {
    cursor: pointer;
    padding-left: 25px;
    padding-top: 25px;
    z-index: 1;
}

.icon-close i {
    color: darkred;
    z-index:1;
}

.menu {
    left: -300px;  /* start off behind the scenes */
    height: 750px;
    position: fixed;
    width: 300px;
}

#background {
    height: 750px;
    width: 300px;
    background-color: #000;
    opacity: .25;
    margin-top: -307px;
}

.menu ul {
    list-style-type: none;
    margin: auto;
    margin-top: 40px;
}

.menu li {
    text-align: center;
    color: #fff;
    font-size: 21px;
    line-height: 50px;
}

我的JS代码:

$(document).ready(function() {
    $('.menu-icon').click(function() {
        $('.menu').animate({
            left: "0px"
        }, 200);
        $('#jumbotron').animate({
            left: "300px"
        }, 200);
        $('.menu-icon').fadeTo("fast", 0);
    });
    /* Then push them back */
    $('.icon-close').click(function() {
        $('.menu').animate({
            left: "-300px"
        }, 200);
        $('#jumbotron').animate({
            left: "0px"
        }, 200);
    });
});

1 个答案:

答案 0 :(得分:1)

尝试使用background-color: rgba(0,0,0,.7);标记不透明度。 我编辑了你的小提琴和作品:https://jsfiddle.net/og1fqfsd/2/

相关问题