【问题标题】:Place Font-Awesome-5 Icon as Bootstrap-4 Card background将 Font-Awesome-5 图标放置为 Bootstrap-4 卡片背景
【发布时间】: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


    【解决方案1】:

    以下代码对我有用。我已经简化了我使用的内容,但您仍然可以得到一个很棒的字体图标作为背景,您可以在其上放置文字:

    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.

    【讨论】:

    • 这不是我想要的。我想你误会了我。一般来说没关系,但我不能在这个图标上放置任何文本。它总是出现在它旁边,例如
    • @b0ss:我已经编辑了代码,现在,我猜,可以满足您的需求
    • 将 col-md-4 col-sm-6 类更改为更小的类(查看 boostrap 文档,col-2 可能会为您解决问题)
    猜你喜欢
    • 2018-04-10
    • 2018-07-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多