【发布时间】:2019-07-08 22:52:55
【问题描述】:
我想使用 Bootstrap-4 使用 Font Awesome 5 图标作为卡片背景图像!
我尝试了所有从互联网上找到的东西,但没有任何效果。
我正在使用 Angular2 (v8) 和 Bootstrap 4。
【问题讨论】:
标签: css twitter-bootstrap bootstrap-4 font-awesome font-awesome-5
我想使用 Bootstrap-4 使用 Font Awesome 5 图标作为卡片背景图像!
我尝试了所有从互联网上找到的东西,但没有任何效果。
我正在使用 Angular2 (v8) 和 Bootstrap 4。
【问题讨论】:
标签: css twitter-bootstrap bootstrap-4 font-awesome font-awesome-5
以下代码对我有用。我已经简化了我使用的内容,但您仍然可以得到一个很棒的字体图标作为背景,您可以在其上放置文字:
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;}
【讨论】: