【问题标题】:Unexpected white background on font-awesome icon字体真棒图标上出现意外的白色背景
【发布时间】:2021-09-05 09:41:02
【问题描述】:

当我使用时,包括一个很棒的字体图标,我无法删除这个意想不到的白色背景。关于如何删除它的任何想法?

HTML 代码:

<div class="notifications-window" id="close-notifications">
<div class="notifications-header">
    <h4>Notifications</h4>
    <button type="button" onclick="closenotifs()"><i class="fas fa-window-close"></i></button>
</div>
<div class="notifications-details">
    <p>Congratulations! Login Reward: 2 credits</p>
    <p>Congratulations! Login Reward: 2 credits</p>
</div>

CSS 代码:

.notifications-window {
width: 350px;
border: 3px solid rgb(0, 0, 0);
background-color: rgb(160, 156, 156);
color: #fff;
border-collapse: collapse;
border-radius: 5px;
text-align: center;
list-style-type: none;
display: inline-block;
}

.notifications-window p {
font-size: small;
padding: 5px;
background: rgb(141, 136, 136);
border-radius: 5px;
margin: 5px;
}

.notifications-details {
overflow-y: auto;
max-height: 350px;
}

.fa-window-close {
display: inline-block;
float: right;
justify-content: right;
cursor: pointer;
text-decoration: none;
text-align: center;
color: #000;
background-color: #fff;
border: none;
outline: none;
transition: background 250ms ease-in-out, 
            transform 150ms ease;
-webkit-appearance: none;
-moz-appearance: none;
}

我附上一张图标样式后的样子

https://i.stack.imgur.com/bfBW6.png

【问题讨论】:

    标签: html css icons font-awesome styling


    【解决方案1】:

    按钮的背景由User Agent Stylesheet添加。你可以探索更多关于user agent stylesheethere的信息。

    但是,您可以通过编写自己的样式来移除按钮的背景。 为此,我为按钮编写了一个.button 类,并从您的.fa-window-close 类中删除了background-color: #fff;。试试这个;

    CSS:

    .notifications-window {
                width: 350px;
                border: 3px solid rgb(0, 0, 0);
                background-color: rgb(160, 156, 156);
                color: #fff;
                border-collapse: collapse;
                border-radius: 5px;
                text-align: center;
                list-style-type: none;
                display: inline-block;
            }
    
                .notifications-window p {
                    font-size: small;
                    padding: 5px;
                    background: rgb(141, 136, 136);
                    border-radius: 5px;
                    margin: 5px;
                }
    
            .notifications-details {
                overflow-y: auto;
                max-height: 350px;
            }
    
            .fa-window-close {
                display: inline-block;
                float: right;
                justify-content: right;
                cursor: pointer;
                text-decoration: none;
                text-align: center;
                color: #000;
                /*background-color: #fff;*/
                border: none;
                outline: none;
                transition: background 250ms ease-in-out, transform 150ms ease;
                -webkit-appearance: none;
                -moz-appearance: none;
            }
            .button {
                background: transparent;
                border: none;
            }
    

    HTML:

    <div class="notifications-window" id="close-notifications">
        <div class="notifications-header">
            <h4>Notifications</h4>
            <button type="button" onclick="closenotifs()" class="button"><i class="fas fa-window-close"></i></button>
        </div>
        <div class="notifications-details">
            <p>Congratulations! Login Reward: 2 credits</p>
            <p>Congratulations! Login Reward: 2 credits</p>
        </div>
     </div>
    

    【讨论】:

    • 啊,那行得通,非常感谢,但这与删除 .fa-window-close 本身中的那些元素不同吗?为什么它不能那样工作?
    • 我很高兴它对你有用。你需要Accept Answer
    猜你喜欢
    • 2014-12-18
    • 2019-02-12
    • 1970-01-01
    • 2019-12-22
    • 2017-04-23
    • 1970-01-01
    • 2014-07-09
    • 2019-01-01
    • 2014-08-05
    相关资源
    最近更新 更多