我使图像看起来像一个可点击的按钮,但现在当我点击它时,不作为超链接?

时间:2015-02-23 15:04:40

标签: javascript html css

这是我的按钮代码:

.info_button {
  width: 220px;
  height: 300px;
  position: absolute;
  overflow: hidden;
  margin-right: 0;
  border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
-webkit-border-radius: 10px;
background: url(http://i.imgur.com/DkdX4Ci.jpg);
background-repeat: no-repeat;
background-position: 0  0;
box-shadow: 3px 3px 20px #363024;
}
.info_button > header {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 20px 10px;
  background: inherit;
  background-attachment: fixed;
  overflow: hidden;
}
.info_button > header::before {
  content: "";
  position: absolute;
  top: -20px;
  left: 0;
  width: 100%;

  background: inherit;
  background-attachment: fixed;
  -webkit-filter: blur(4px);
  filter: blur(4px);
}
.info_button > header::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5)
}

.info_button > header  p a {
  margin: 0;
  color: white;
  position: relative;
  z-index: 0;
}

.info_button:hover{ 
box-shadow: 1px 1px 5px #363024;
-webkit-box-shadow: 1px 1px 5px #363024;
-moz-box-shadow: 1px 1px 5px #363024;
position:relative;
top:7px;
margin: 0;
} 

这是我的HTML:

<div class="info_button" style="position:absolute; left:190px; top:25px;">
<header>
<p><a href="https://www.google.com" target="_self"><span id="info_button">              BoilerPlate of my Mansion</span></a></p>
</header>
</div>

这是我工作的小提琴: http://jsfiddle.net/veniarya/ygosqouh/

按钮的功能与我想要的完全一样,但在点击时不会链接到超链接。如果我遗失某些东西或需要添加某些东西,请告诉我。 感谢。

3 个答案:

答案 0 :(得分:1)

为什么不做你

<a href="..."> <img src="..."> </a>

答案 1 :(得分:1)

问题是你对锚标签的z-index设置为0;一旦你将它改为正的z指数,即100,现在可以点击链接。

.info_button > header p a {
    margin: 0;
    color: white;
    position: relative;
    z-index: 100;
}

至于可以点击整个按钮,你必须像这样修改HTML:

<a href="https://www.google.com" target="_blank">
   <div class="info_button" style="position:relative; left:190px; top:25px;">
        <header>
          <p><span id="info_button">
             BoilerPlate of my Mansion</span></p>
        </header>
    </div>
</a>

答案 2 :(得分:0)

所以我的问题的答案来自@ Donte'Trumble。 CSS代码:

.info_button {
  width: 220px;
  height: 300px;
  position: absolute;
  overflow: hidden;
  margin-right: 0;
  border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
-webkit-border-radius: 10px;
background: url(http://i.imgur.com/DkdX4Ci.jpg);
background-repeat: no-repeat;
background-position: 0  0;
box-shadow: 3px 3px 20px #363024;
}
.info_button > header {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 20px 10px;
  background: inherit;
  background-attachment: fixed;
  overflow: hidden;
}
.info_button > header1::before {
  content: "";
  position: absolute;
  top: -20px;
  left: 0;
  width: 100%;

  background: inherit;
  background-attachment: fixed;
  -webkit-filter: blur(4px);
  filter: blur(4px);
}
.info_button > header::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5)
}

.info_button > header  p {
  margin: 0;
  color: white;
  position: relative;
  z-index: 0;
}

.info_button:hover{ 
box-shadow: 1px 1px 5px #363024;
-webkit-box-shadow: 1px 1px 5px #363024;
-moz-box-shadow: 1px 1px 5px #363024;
position:relative;
top:7px;
margin: 0;
} 

HTML:

<a href="https://www.google.com" target="_blank">
<div class="info_button" style="position:absolute; left:190px; top:25px;">
    <header><p><span id="info_button">BoilerPlate of my Mansion</span></p>
    </header>
        </div>
    </a>

工作小提琴:http://jsfiddle.net/veniarya/ygosqouh/ 问题在于我的z-index,必须使它成为正整数,因此从0改为100,再次感谢@ Donte'Truble。