在单个导航项上添加box-shadow

时间:2016-03-12 04:35:02

标签: html css css3

我正在制作我自己的网站,而且对于菜单,我很难过。这就是菜单现在的样子。

enter image description here

除了一件事,一切都很完美!我正在尝试将“盒子阴影”添加到“博客”菜单项中,如果放大,您将在“博客”的左侧和顶部看到盒子阴影。但它没有出现在右侧。看起来“关于”是重叠的。

盒子阴影代码没有问题。但是,这是:

box-shadow: 0 0 10px 3px rgba(0,0,0,0.12);
-webkit-box-shadow: 0 0 10px 3px rgba(0,0,0,0.12);
-moz-box-shadow: 0 0 10px 3px rgba(0,0,0,0.12);

这是HTML文件:

<footer>
  <nav class="main">
    <ul>
      <li style="background: #33A2FF;">
        <a href="#">
          <span aria-hidden="true" data-icon="&#xec02;" class="icon icon-briefcase"></span>
          PROJECTS
        </a>
      </li>
      <li style="background: #22E886;">
        <a href="#">
          <span aria-hidden="true" data-icon="&#xe92e;" class="icon icon-bucket"></span>
          DESIGNS
        </a>
      </li>
      <li style="background: #ACFF32;">
        <a href="#" class="highlight">
          <span aria-hidden="true" data-icon="&#xe91c;" class="icon icon-pen"></span>
          BLOG
        </a>
      </li>
      <li style="background: #E8BA22;">
        <a href="#">
          <span aria-hidden="true" data-icon="&#xec27;" class="icon icon-brain"></span>
          ABOUT
        </a>
      </li>
      <li style="background: #FF6F25;">
        <a href="#">
          <span aria-hidden="true" data-icon="&#xea35;" class="icon icon-mailbox"></span>
          CONTACT
        </a>
      </li>
    </ul>
  </nav>
</footer>

这是CSS文件:

footer{
  bottom: 0;
  // height: 100px;
  left: 0;
  overflow: hidden;
  position: absolute;
  width: 100%;

  nav.main{}

  nav.main ul{
    list-style-type: none;
    margin-bottom: 0;
    padding-left: 0;
  }

  nav.main ul li{
    display: inline-block;
    float: left;
    line-height: 1;
    margin-top: 1.5rem;
    text-align: center;
    width: 20%;
  }

  nav.main ul li span{
    display: block;
    font-size: 5rem;
    margin-bottom: 1rem;
  }

  nav.main ul li a{
    color: #2D2D2D;
    display: block;
    font-size: 2rem;
    padding: 2rem;
  }

  nav.main ul li a.highlight{
    background-color: #ACFF32;
    box-shadow: 0 0 10px 3px rgba(0,0,0,0.12);
    -webkit-box-shadow: 0 0 10px 3px rgba(0,0,0,0.12);
    -moz-box-shadow: 0 0 10px 3px rgba(0,0,0,0.12);

    border-radius: 5px 5px 0 0;
    margin-top: -1.5rem;
    padding-top: 3.5rem;
  }
}

还有一件事,这对你来说很重要。如果我将背景添加到导航标签并删除菜单项上的所有颜色,则框阴影将起作用。因此,分别定义颜色会导致问题。

非常感谢。

1 个答案:

答案 0 :(得分:3)

您需要使活动标签的z-index高于其他标签,因此投影保持在最顶层:

因此请将其添加到nav.main ul li a.highlight

position: relative;
z-index: 2;
相关问题