使整个div区域可点击

时间:2015-05-23 20:58:15

标签: html css

我知道的这个愚蠢的问题,但我会围成一圈......我有这个html ....

<div class="navbtn"> <p><a class="nav-toggle" href="#"><span></span></a>Menu</p>
    </div>

“nav-toggle”类指的是位于div navbtn内的汉堡包,旁边有单词菜单....我基本上想让整个区域的navbtn可以点击,因为我可以只需点击汉堡包图标本身就没有别的...... navbtn和nav-toggle(汉堡包)的CSS如下:

.nav-toggle { position: absolute; left: 15px; top: 25px; outline: 0; z-index : 9999; display: inline-block;}

.nav-toggle { cursor: pointer;}
.nav-toggle span, .nav-toggle span:before, .nav-toggle span:after {
  cursor: pointer;
  height: 5px;
  width: 45px;
  background: white;
  position: absolute;
  display: inline-block;
  content: '';
  outline: 0;
}
.nav-toggle span:before {
  top: -10px; 
}
.nav-toggle span:after {
  bottom: -10px;
}
input::-moz-focus-inner { 
  border: 0; 
}
.nav-toggle span, .nav-toggle span:before, .nav-toggle span:after {
  transition: all 500ms ease-in-out;
  outline: 0;
}
.nav-toggle.active span {
  background-color: transparent;
  outline: 0;
}
.nav-toggle.active span:before, .nav-toggle.active span:after {
  top: 0;
  outline: 0;
}
.nav-toggle.active span:before {
  transform: rotate(45deg);
}
.nav-toggle.active span:after {
  transform: rotate(-45deg);
}

和navbtn div

.navbtn {
  position: fixed;
  left: 10px;
  top: 10px;
  display: inline-block;
  padding: 8px;
  background-color: transparent;
  width: auto;
  color: #ffffff;
  cursor: pointer;

}
.navbtn p {
    margin: 0;
    padding: 0 2.4em 0.6em;
    font-size: 1.7em;
    line-height: 1.5;
    color : #fff;
    cursor: pointer;
}

1 个答案:

答案 0 :(得分:3)

把锚放在div之外?

<a href="#">
    <div class="navbtn">
        <i class="nav-toggle"></i>
        <p><span></span>Menu</p>
    </div>
</a>

注意我已将<a>内的<div>更改为<i>,这是某些字体图标包将执行的操作。我之所以这样做,是因为我发现如果我把它作为一个跨度,那么你会有一些混乱的东西。