【问题标题】:Hyperlink in CSS button not working and leading anywhere [duplicate]CSS按钮中的超链接不起作用并在任何地方领先[重复]
【发布时间】:2021-07-07 21:44:15
【问题描述】:

当我点击按钮时,它不会指向超链接,我点击后它只会上下移动。我尝试重新链接或使用其他链接来解决此问题,但无济于事。看来我的 html 代码是正确的,但我可能在代码中遗漏了一个小错误。

这是我的代码:

.btn {
    background-color:transparent;
    border-radius:28px;
    border:1px solid #702F8A;
    display:inline-block;
    cursor:pointer;
    color:#702F8A;
    font-family:Tahoma;
    font-size:14px;
padding:4px 13px;
    text-decoration:none;
position: absolute;
bottom: 4.5%

}
.btn:hover {
    background-color:#702F8A;
border-color:#702F8A;
}
.btn:active {
    position:relative;
    top:1px;
}
.flex-container {
    display: flex;
    justify-content: center;
}
<section class="px-4 cards_invitations">
<div class="container">
<div class="row">
<div class="col-12 col-md-6 col-lg-4 py-3 text-center border"><a href="https://www.example.com/"><img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Accessories_Collage - Copy 2.png" /></a>
<p class="my-3" style="font-size:18px;">&nbsp;</p>

<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Accessories <i class="far fa-chevron-right pl-1"></i></a></div>
</div>

<div class="col-12 col-md-6 col-lg-4 py-3 text-center border"><a href="https://www.example.com/"><img class="img-fluid" src="/images/contentimages/images/Activewear - Copy 1.png" /></a>

<p class="my-3" style="font-size:18px;">&nbsp;</p>

<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Active Wear <i class="far fa-chevron-right pl-1"></i></a></div>
</div>

<div class="col-12 col-md-6 col-lg-4 py-3 text-center border"><a href="https://www.example.com/"><img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Bags_Backpacks_ - Copy 1.png" /></a>

<p class="my-3" style="font-size:18px;">&nbsp;</p>

<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Bags <i class="far fa-chevron-right pl-1"></i></a></div>
</div>

【问题讨论】:

    标签: html css button hyperlink href


    【解决方案1】:

    删除 CSS 代码中您编写 bottom: 4.5% 的部分

    这样做的目的是将所有元素与您创建的那个类 (btn) 一起放置,并将它们全部放在彼此之上。发生这种情况时,浏览器不知道将用户重定向到哪里,这就是为什么它会像您所说的那样出现小故障。当你删除它时,所有的链接应该会再次工作。

    此外,这并不能真正解决您遇到的问题,但最后,您缺少 2 个结束 div 标记和 1 个结束部分标记。

    完全正确的代码:

    <style type="text/css">
       .btn {
       background-color:transparent;
       border-radius:28px;
       border:1px solid #702F8A;
       display:inline-block;
       cursor:pointer;
       color:#702F8A;
       font-family:Tahoma;
       font-size:14px;
       padding:4px 13px;
       text-decoration:none;
       position: absolute;
       }
       .btn:hover {
       background-color:#702F8A;
       border-color:#702F8A;
       }
       .btn:active {
       position:relative;
       top:1px;
       }
       .flex-container {
       display: flex;
       justify-content: center;
       }
    </style>
    <section class="px-4 cards_invitations">
       <div class="container">
          <div class="row">
             <div class="col-12 col-md-6 col-lg-4 py-3 text-center border">
                <a href="https://www.example.com/"><img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Accessories_Collage - Copy 2.png" /></a>
                <p class="my-3" style="font-size:18px;">&nbsp;</p>
                <div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Accessories <i class="far fa-chevron-right pl-1"></i></a></div>
             </div>
             <div class="col-12 col-md-6 col-lg-4 py-3 text-center border">
                <a href="https://www.example.com/"><img class="img-fluid" src="/images/contentimages/images/Activewear - Copy 1.png" /></a>
                <p class="my-3" style="font-size:18px;">&nbsp;</p>
                <div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Active Wear <i class="far fa-chevron-right pl-1"></i></a></div>
             </div>
             <div class="col-12 col-md-6 col-lg-4 py-3 text-center border">
                <a href="https://www.example.com/"><img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Bags_Backpacks_ - Copy 1.png" /></a>
                <p class="my-3" style="font-size:18px;">&nbsp;</p>
                <div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Bags <i class="far fa-chevron-right pl-1"></i></a></div>
             </div>
          </div>
       </div>
    </section>
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2017-05-23
      • 2013-02-24
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      相关资源
      最近更新 更多