如何使引导卡可点击?

Posted

技术标签:

【中文标题】如何使引导卡可点击?【英文标题】:How to make bootstrap card clickable? 【发布时间】:2019-06-06 19:26:31 【问题描述】:

为了在我的网站上使用,我正在尝试使引导卡可点击。 但是当我用“ahref”链接包装盒子时,会有很多样式问题。 盒子变小了。我尝试了很多替代方案,但我找不到我遇到问题的原因。

你也可以找到https://codepen.io/snarex/pen/ebQdgj,我做了一些测试。

section 
    padding-top: 4rem;
    padding-bottom: 5rem;
    background-color: #f1f4fa;

.wrap 
    display: flex;
    background: white;
    padding: 1rem 1rem 1rem 1rem;
    border-radius: 0.5rem;
    box-shadow: 7px 7px 30px -5px rgba(0,0,0,0.1);
    margin-bottom: 2rem;


.wrap:hover 
    background: linear-gradient(135deg,#6394ff 0%,#0a193b 100%);
    color: white;


.ico-wrap 
    margin: auto;


.mbr-iconfont 
    font-size: 4.5rem !important;
    color: #313131;
    margin: 1rem;
    padding-right: 1rem;

.vcenter 
    margin: auto;


.mbr-section-title3 
    text-align: left;

h2 
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;

.display-5 
    font-family: 'Source Sans Pro',sans-serif;
    font-size: 1.4rem;

.mbr-bold 
    font-weight: 700;


 p 
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    line-height: 25px;

.display-6 
    font-family: 'Source Sans Pro',sans-serif;
    font-size: 1re
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<section>
<div class="container">

	
		<div class="row mbr-justify-content-center">

            <div class="col-lg-6 mbr-col-md-10">
                <div class="wrap">
                    <div class="ico-wrap">
                        <span class="mbr-iconfont fa-volume-up fa"></span>
                    </div>
                    <div class="text-wrap vcenter">
                        <h2 class="mbr-fonts-style mbr-bold mbr-section-title3 display-5">Stay <span>Successful</span></h2>
                        <p class="mbr-fonts-style text1 mbr-text display-6">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 mbr-col-md-10">
                <div class="wrap">
                    <div class="ico-wrap">
                        <span class="mbr-iconfont fa-calendar fa"></span>
                    </div>
                    <div class="text-wrap vcenter">
                        <h2 class="mbr-fonts-style mbr-bold mbr-section-title3 display-5">Create
                            <span>An Effective Team</span>
                        </h2>
                        <p class="mbr-fonts-style text1 mbr-text display-6">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 mbr-col-md-10">
                <div class="wrap">
                    <div class="ico-wrap">
                        <span class="mbr-iconfont fa-globe fa"></span>
                    </div>
                    <div class="text-wrap vcenter">
                        <h2 class="mbr-fonts-style mbr-bold mbr-section-title3 display-5">Launch
                            <span>A Unique Project</span>
                        </h2>
                        <p class="mbr-fonts-style text1 mbr-text display-6">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 mbr-col-md-10">
                <div class="wrap">
                    <div class="ico-wrap">
                        <span class="mbr-iconfont fa-trophy fa"></span>
                    </div>
                    <div class="text-wrap vcenter">
                        <h2 class="mbr-fonts-style mbr-bold mbr-section-title3 display-5">Achieve <span>Your Targets</span></h2>
                        <p class="mbr-fonts-style text1 mbr-text display-6">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum</p>
                    </div>
                </div>
            </div>

            

            
        </div>

</div>

</section>

【问题讨论】:

【参考方案1】:

你可以试着让你的a标签position: absolute;像这样......

html

<div class="wrap">
  <a href="#"></a>
</div>

CSS

.wrap
  position: relative;

.wrap a
  position: absolute;
  width:100%;
  height:100%;
  top:0px;
  left:0px;

a 标签现在位于您的卡片顶部,应该会根据需要随卡片一起扩大和缩小。您还可以将border-radius 添加到a 标签以匹配您卡片的角。

我还更新了您的 CODEPEN,以便您可以在检查器中看到更改,从而更好地了解发生了什么。

【讨论】:

以上是关于如何使引导卡可点击?的主要内容,如果未能解决你的问题,请参考以下文章

使引导卡完全可点击

如何使引导表行可点击? [复制]

如何使整个引导程序缩略图可点击(适用于手机和平板电脑)

可点击的 div 充当按钮功能 react js

使材质选项卡可滚动

在 React 中,如何使锚点在点击时不执行任何操作?