将Font-Awesome-5图标放置为Bootstrap-4卡背景

时间:2019-07-05 14:47:23

标签: css twitter-bootstrap bootstrap-4 font-awesome font-awesome-5

我想使用Bootstrap-4将Font Awesome 5图标用作卡片背景图像!

我尝试了从互联网上发现的所有内容,但没有任何效果。

我正在使用Angular2(v8)和Bootstrap 4。

1 个答案:

答案 0 :(得分:0)

以下代码对我有用。我简化了我的操作,但是您仍然会得到一个超棒的字体图标作为背景,并且可以在其上方放置文本:

HTML:

<div class="container-fluid">
<div class="row">

    <div class="col-md-4 col-sm-6 d-flex">
    <div class="class-box">
    <div class="bg-primary">
    <i class="fa fa-question big-centered-icon"></i>
    </div>
    <div class="box-content">
    <h3 class="title-bg text-outline"><Strong>TITLE</Strong></h3>   
    <h4 class="title-bg text-outline">Subtitle</h4>
    <h4 class="title-bg text-outline"><Strong> Subtitle</Strong></h4>
    </div>
    </div>
    </div>

    <div class="col-md-4 col-sm-6 d-flex">
    <div class="class-box">
    <div class="bg-primary">
    <i class="fa fa-question big-centered-icon"></i>
    </div>
    <div class="box-content">
    <h3 class="title-bg text-outline"><Strong>HELLO</Strong></h3>   
    <h3 class="title-bg text-outline"><Strong> 2nd HELLO</Strong></h3>
    <h3 class="title-bg text-outline"><Strong> 3rd HELLO</Strong></h3>
    </div>
    </div>
    </div>

</div>
</div>

CSS:

.big-centered-icon {
font-size: 144px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex; /* add */
justify-content: center; /* add to align horizontal */
align-items: center; /* add to align vertical */
}

.class-box{ text-align:center;position:relative;margin:8px;width: 100%;padding-bottom: 75%}
div.class-box > div { position:absolute;top:0;bottom:0;left:0;right:0;overflow:hidden;padding-top:15%}
.class-box .title-bg{font-size:24px;color:#000;}

See the working fiddle.