Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS\HTML - How to add Ionicons to CSS "content" property?

Tags:

html

css

ionicons

I'm using a custom switch toggle (from here) and I want to add an icon instead of regular text. When I paste the Ionicons code to the CSS content property it appears as a rectangle (some indication for the fact the character\font was not found). How do I get pass this?

EDIT: I forgot to add, I have included the CSS from CDN.

JSfiddle

Switch CSS:

.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:

    <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>
like image 857
Alex Avatar asked May 03 '15 09:05

Alex


People also ask

How do I link HTML to Ionicons?

To embed an Ionicon in HTML all you have to do is copy the scripts from the installation section of the Ionicons and paste them in your HTML document. Afterward, select the Ionicon of your choice, copy the component code and paste it into your HTML document.

How do you use ionic Ionicons?

If you're using Ionic Framework, Ionicons is packaged by default, so no installation is necessary. Want to use Ionicons without Ionic Framework? Place the following <script> near the end of your page, right before the closing </body> tag, to enable them.

How do you increase icon size in CSS?

Larger Icons To increase the size of icons relative to its container, use icon-large , icon-2x , icon-3x , or icon-4x . Increase the icon size by using the icon-large (33% increase), icon-2x , icon-3x , or icon-4x classes.


1 Answers

You're missing a @font-face declaration that imports the "Ionicons" font face, plus the .onoffswitch-inner:after declaration doesn't specify the font-family: "Ionicons";.

I've extracted the Ionicons font declaration from their css and added it to a forked jsFiddle.

like image 107
ckuijjer Avatar answered Sep 25 '22 01:09

ckuijjer