无法让我的导航过去在翻滚时淡入的头部

时间:2014-12-22 19:32:14

标签: html css z-index rollover

我正在一个网站上工作,我需要一个基本上是透明盒子的标题,当你翻过它时它会消失(参见horizo​​nsupply.co)。我到目前为止已经成功创建了标题以及徽标,并且它完美地工作,但是当我尝试放入导航时,它或者位于淡入框下面,不允许点击链接(我使用z -index也是如此)或者如果我将导航的z-index设置为高于淡入框所在的数字,则不允许该框在翻转时淡入。希望这是有道理的。基本上我正在尝试重新创建horizo​​nsupply.co正在发生的事情。

这是我的html:

<div id="logo" >
    <img src="images/weblogo.png" alt="weblogo">
</div>

<div id="navigation" class="clearfix">
    <div id="navlinks"> 
        <ul>
            <a href="#"><li>ABOUT</li></a>
            <a href="#"><li>EPISODES</li></a>
            <a href="#"><li>CONTACT</li></a>
        </ul>
    </div>
</div>

<div id="header"></div>

<div id="main" class="clearfix">
    <img src="images/1415210745666.jpeg" alt="1415210745666" width="100%" height="675">

    <div id="content">
        <div id="episodebox"></div>
        <div id="episodebox2"></div>
        <div id="episodebox3"></div>
    </div>
</div>

这是我的CSS:

#header{
    width:100%;
    height:205px;
    background-color:#2D2D2D;
    position:absolute;
    z-index:1;

     opacity: 0; /* Change this to .5 for 50% opacity */
    -webkit-transition: .5s;
       -moz-transition: .5s;
        -ms-transition: .5s;
         -o-transition: .5s;
            transition: .5s;    
}

#header:hover {
     opacity: 0.87;
}

#body{
    background-color:#ffffff;
}

.img{
     max-width:100%; 
     max-height:100%;
}

#logo{
     position:absolute;
     width:auto;
     height:auto;
     padding-left:25px;
     padding-top:10px;
     z-index:3;
}

#navigation.clearfix{
    position:absolute;
    width:100%;
    height:auto;
    padding-top:160px;
    padding-left:15px;
    z-index:1;
    clear:both;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    margin-top:auto;
    margin-bottom:auto;
}

li{
    display:block;
    float:left;
    padding:1%;
}

a:link {
    text-decoration: none;
    color: #F46969;
    font-family: 'Roboto', sans-serif;
    font-weight:500;
}

#main.clearfix{
    clear:both;
}

#content{
    width:960px;
    height:900px;
    margin-left:auto;
    margin-right:auto;
    background-color:#ffffff;
    margin-top:150px;
}

#episodebox{
    width:270px;
    height:50px;
    background-color:#ffa9a9;
    margin-left:37px;
    margin-right:18px;
    float:left;
}

#episodebox2{
    width:270px;
    height:50px;
    background-color:#ffa9a9;
    margin-left:18px;
    margin-right:18px;
    float:left;
}

#episodebox3{
    width:270px;
    height:50px;
    background-color:#ffa9a9;
    margin-left:18px;
    margin-right:37px;
    float:left;
}

2 个答案:

答案 0 :(得分:0)

有很多种方法,其中一个最简单的解决方案是用标题div包装整个内容(徽标,链接等),然后操纵background-color而不是opacity

#header {
  width: 100%;
  height: 205px;
  background-color: transparent;
  position: absolute;
  z-index: 1;
  -webkit-transition: .5s;
  -moz-transition: .5s;
  -ms-transition: .5s;
  -o-transition: .5s;
  transition: .5s;
}
#header:hover {
  background-color: rgba(45, 45, 45, .85);
}
#body {
  background-color: #ffffff;
}
.img {
  max-width: 100%;
  max-height: 100%;
}
#logo {
  position: absolute;
  width: auto;
  height: auto;
  padding-left: 25px;
  padding-top: 10px;
  z-index: 3;
}
#navigation.clearfix {
  position: absolute;
  width: 100%;
  height: auto;
  padding-top: 160px;
  padding-left: 15px;
  z-index: 1;
  clear: both;
}
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  margin-top: auto;
  margin-bottom: auto;
}
li {
  display: block;
  float: left;
  padding: 1%;
}
a:link {
  text-decoration: none;
  color: #F46969;
  font-family: 'Roboto', sans-serif;
  font-weight: 500;
}
#main.clearfix {
  clear: both;
}
#content {
  width: 960px;
  height: 900px;
  margin-left: auto;
  margin-right: auto;
  background-color: #ffffff;
  margin-top: 150px;
}
#episodebox {
  width: 270px;
  height: 50px;
  background-color: #ffa9a9;
  margin-left: 37px;
  margin-right: 18px;
  float: left;
}
#episodebox2 {
  width: 270px;
  height: 50px;
  background-color: #ffa9a9;
  margin-left: 18px;
  margin-right: 18px;
  float: left;
}
#episodebox3 {
  width: 270px;
  height: 50px;
  background-color: #ffa9a9;
  margin-left: 18px;
  margin-right: 37px;
  float: left;
}
<div id="header">
  <div id="logo">
    <img src="http://placekitten.com/g/50/50" alt="weblogo">
  </div>

  <div id="navigation" class="clearfix">
    <div id="navlinks">
      <ul>
        <a href="#">
          <li>ABOUT</li>
        </a>
        <a href="#">
          <li>EPISODES</li>
        </a>
        <a href="#">
          <li>CONTACT</li>
        </a>
      </ul>
    </div>
  </div>

</div>

<div id="main" class="clearfix">
  <img src="http://placekitten.com/g/700/700" alt="1415210745666" width="100%" height="675">

  <div id="content">
    <div id="episodebox"></div>
    <div id="episodebox2"></div>
    <div id="episodebox3"></div>
  </div>
</div>

答案 1 :(得分:0)

Marcelo给出了最佳解决方案,我建议在li内部移动标签

<ul>
    <li><a href="#">Link1</li></a>
    <li><a href="#">Link2</li></a>
    <li><a href="#">Link3</li></a>
</ul>