微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

伪图像背景绝对定位导致锚标签损坏 - 如何修复?

如何解决伪图像背景绝对定位导致锚标签损坏 - 如何修复?

当我向 div 容器的 tge pesudo 元素添加背景图像时,我正在努力弄清楚为什么这个锚标记链接不起作用。

导致链接断开的原因是“contact-me”伪元素的“绝对”定位。但是如果我删除它,我就会丢失图像。如何保留图像并使锚标记链接起作用?有什么建议吗?

HTML:

<div id="contact-me">

<h2>Contact</h2>

<h3><a class="btn" href = "mailto:email@gmail.com">email@gmail.com</a></h3>

</div>

CSS:


#contact-me {
  background:      background: -webkit-linear-gradient(70deg,#e6739f 30%,rgba(0,0) 30%),-webkit- linear-gradient(30deg,#cc0e74 60%,#790c5a 60%);
  background: -o-linear-gradient(70deg,-o-linear-gradient(30deg,#790c5a 60%);
  background: -moz-linear-gradient(70deg,-moz-linear-gradient(30deg,#790c5a 60%);
  background: linear-gradient(70deg,linear-gradient(30deg,#cc0e74     60%,#790c5a 60%);
  color: #f5f5f5;
  position: relative;
  margin-top: 100px;
  padding-top: 5px;
  padding-bottom: 60px;

}

#contact-me:after {
       content: "";
       background: url("http://www.transparenttextures.com/patterns/cubes.png");
       position: absolute;
       top: 0px;
       right: 0px;
       bottom: 0px;
       left: 0px;
       opacity: 0.9;
       width: 100%;
       height: 100%;
}

.btn {
  cursor: pointer;
  color: #fffafa;
  z-index: 5;
}

任何帮助都会得到极大的赞赏!

解决方法

试试这个:

.btn {
  cursor: pointer;
  color: #fffafa;
  z-index: 5;
  position:relative
}
,

你为什么在联系我 ID 下插入 background: background:? 使您的 .btn位置:相对;

下面的代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <title>Document</title>
  <style>
    

    #contact-me {
  background: -webkit-linear-gradient(70deg,#e6739f 30%,rgba(0,0) 30%),-webkit- linear-gradient(30deg,#cc0e74 60%,#790c5a 60%);
  background: -o-linear-gradient(70deg,-o-linear-gradient(30deg,#790c5a 60%);
  background: -moz-linear-gradient(70deg,-moz-linear-gradient(30deg,#790c5a 60%);
  background: linear-gradient(70deg,linear-gradient(30deg,#cc0e74     60%,#790c5a 60%);
  color: #f5f5f5;
  position: relative;
  margin-top: 100px;
  padding-top: 5px;
  padding-bottom: 60px;

}

#contact-me:after {
       content: "";
       background: url("http://www.transparenttextures.com/patterns/cubes.png");
       position: absolute;
       top: 0px;
       right: 0px;
       bottom: 0px;
       left: 0px;
       opacity: 0.9;
       width: 100%;
       height: 100%;
}

.btn {
  position: relative;
  cursor: pointer;
  color: #fffafa;
  z-index: 5;
}
  </style>
</head>
<body>
  <div id="contact-me">

    <h2>Contact</h2>
    
    <h3><a class="btn" href = "mailto:email@gmail.com">email@gmail.com</a></h3>
    
    </div>
</body>
</html>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。