首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS\HTML -如何向CSS "content“属性中添加Ionicons?

问CSS\HTML -如何向CSS "content“属性中添加Ionicons?
EN

Stack Overflow用户
提问于 2015-05-03 09:34:40
回答 4查看 53.6K关注 0票数 15

我使用自定义的switch切换(从这里),我想添加一个图标,而不是普通文本。当我将Ionicons代码粘贴到CSS content属性时,它显示为一个矩形(没有找到字符\content)。我怎么通过这个?

编辑:我忘了添加,我已经包含了来自CDN的CSS。

JSfiddle

切换CSS:

代码语言:javascript
复制
.onoffswitch {
    position: relative; 
    width: 108px;
    -webkit-user-select:none; 
    -moz-user-select:none; 
    -ms-user-select: none;
}
.onoffswitch-checkbox {
    display: none;
}
.onoffswitch-label {
    display: block; 
    overflow: hidden; 
    cursor: pointer;
    border: 2px solid #999999; 
    border-radius: 30px;
}
.onoffswitch-inner {
    display: block; 
    width: 200%; 
    margin-left: -100%;
    -moz-transition: margin 0.3s ease-in 0s; 
    -webkit-transition: margin 0.3s ease-in 0s;
    -o-transition: margin 0.3s ease-in 0s; 
    transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
    display: block; 
    float: left; width: 50%; 
    height: 40px; padding: 0; 
    line-height: 38px;
    font-size: 14px; 
    color: white; 
    font-weight: bold;
    -moz-box-sizing: border-box; 
    -webkit-box-sizing: border-box; 
    box-sizing: border-box;
}
.onoffswitch-inner:before {
    content: "ON";
    padding-left: 10px;
    background-color: #FFFFFF; 
    color: #BABABA;
}
.onoffswitch-inner:after {
    content: "\f425"; /* <--------THE ICON GOES HERE */
    padding-right: 10px;
    background-color: #8035A7; 
    color: #FFFFFF;
    text-align: right;
}
.onoffswitch-switch {
    display: block; 
    width: 41px; margin: -1.5px;
    background: #FFFFFF;
    border: 2px solid #999999; 
    border-radius: 50px;
    position: absolute; 
    top: 0; 
    bottom: 0; 
    right: 66px;
    -moz-transition: all 0.3s ease-in 0s; 
    -webkit-transition: all 0.3s ease-in 0s;
    -o-transition: all 0.3s ease-in 0s; 
    transition: all 0.3s ease-in 0s; 
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
    margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
    right: 0px; 
}

HTML:

代码语言:javascript
复制
    <div class="onoffswitch">
        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
        <label class="onoffswitch-label" for="myonoffswitch">
            <p id="impressions_meter_text">Impressions meter</p>
            <span class="onoffswitch-inner"></span>
            <span class="onoffswitch-switch"></span>
        </label>
    </div>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-05-03 09:48:01

您缺少了一个导入"Ionicons“字体面板的@font-face声明,加上.onoffswitch-inner:after声明没有指定font-family: "Ionicons";。

我从他们的css中提取了Ionicons字体声明,并将其添加到分叉式jsFiddle中。

票数 20
EN

Stack Overflow用户

发布于 2015-05-03 11:00:47

你省略了字体-家庭属性..。当您将字体图标中的代码使用到CSS content属性中时,您必须这样做:

代码语言:javascript
复制
.custom-icon:after {
    content: "\f425";
    font-family: "the name of the font icon you are using";
}

就这样:P

票数 7
EN

Stack Overflow用户

发布于 2017-01-17 12:20:20

使用离子V2

要在css中使用https://ionicframework.com/docs/v2/ionicons/中的离子图标,只需这样做即可。

代码语言:javascript
复制
.yourclass {
        font-family: "Ionicons";
        content: "\f3d1";
}

这将打印: <ion-icon name="arrow-forward"></ion-icon>

您可以在以下文件中找到内容十六进制:

代码语言:javascript
复制
node_modules/ionic-angular/css/ionic.css:

node_modules/ionic-angular/css/ionic.dark.css
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30012304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档