How to implement custom icon font with CSS - html

I'm wondering how to implement these icons using CSS.
Here is the CSS:
.icon {
font-family: 'spokeo';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
position: relative;
}
.search_icon:before { content:'\e001'; }
.down_arrow_icon:before { content:'\e002'; }
.up_arrow_icon:before { content:'\e003'; }
...etc
And the HTML:
<div>
<i class="toc_icon"></i>Table of Contents
</div>
Any ideas?

The first thing you will need to do is import the font using #font-face in the CSS.
You will need the four major filetypes for the icons to have cross-browser functionality. These are eot ttf svg and woff. A good free resource for icon font sets is fontello.com:
#font-face {
font-family: 'spokeo';
src: url('path/to/spokeo.eot');
src: url('path/to/spokeo.eot?#iefix') format('embedded-opentype'),
url('path/to/spokeo.woff') format('woff'),
url('path/to/spokeo.ttf') format('truetype'),
url('path/to/spokeo.svg#spokeo') format('svg');
font-weight: normal;
font-style: normal;
}
The above imports the font to the browser for use later when you call the icons in your page.
You will now define the .icon class in the stylesheet like you did in your example:
.icon {
font-family: 'spokeo';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
position: relative;
}
.search_icon:before { content:'\e001'; }
.down_arrow_icon:before { content:'\e002'; }
.up_arrow_icon:before { content:'\e003'; }
And then in your HTML you would write in the icon class as well as the specific class in your icon so that it includes all of the styles associated with all icons and then the specific icon contents, like this:
<div>
<i class="icon search_icon"></i>Search
<i class="icon down_arrow_icon"></i>Down
etc...
</div>

full code with working demo
jfFiddle
html
<div>
<i class="icon search_icon"></i> Search
</div>
<div>
<i class="icon down_arrow_icon"></i> Down Arrow
</div>
<div>
<i class="icon up_arrow_icon"></i> Up Arrow
</div>
css
#font-face {
font-family: 'spokeo';
src: url('http://getbootstrap.com/fonts/glyphicons-halflings-regular.eot');
src: url('http://getbootstrap.com/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
url('http://getbootstrap.com/fonts/glyphicons-halflings-regular.woff') format('woff'),
url('http://getbootstrap.com/fonts/glyphicons-halflings-regular.ttf') format('truetype'),
url('http://getbootstrap.com/fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');
}
div {
margin-bottom: 5px;
}
.icon {
font-family: 'spokeo';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
position: relative;
}
.search_icon:before {
content: '\e003';
}
.down_arrow_icon:before {
content: '\e094';
}
.up_arrow_icon:before {
content: '\e093';
}

Related

How do I fix the positioning of material icons?

I am attempting to fix the offset between the text and the material icon.
I have no position editing CSS.
This is the HTML for the two elements.
<i class="material-icons md-18 inline">mail</i>
<h6 class="inline">info#ex.com</h6>
The CSS from here https://fonts.googleapis.com/icon?family=Material+Icons
I attempted to use things like margin and that just offsets the entire div.
The HTML and CSS codes you have are as follows:
/* fallback */
#font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialicons/v134/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
<i class="material-icons md-18 inline">mail</i>
<h6 class="inline">info#ex.com</h6>
The above snippet outputs this:
To have the text on the same line as the icon, set the text's display to inline and add a left margin to it
h6.inline {
display: inline;
margin-left: 10px;
}
After modifying, the resultant code:
/* fallback */
#font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialicons/v134/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
h6.inline {
display: inline;
margin-left: 10px;
}
<i class="material-icons md-18 inline">mail</i>
<h6 class="inline">info#ex.com</h6>
You can try by putting the icons and the <h6> into a <div> tag. After that you have to make the display of that div flex.
Here is the code:-
.align-div{
display:flex;
align-items:center;
justify-content:center;
flex-direction:row;
}
<div class = "align-div">
<i class="material-icons md-18 inline">mail</i>
<h6 class="inline">info#ex.com</h6>
</div>
Same goes with the phone section place them in a div and same process goes on.
/* fallback */
#font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialicons/v134/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
.wrapper {
display: flex;
align-items: center;
}
<div class="wrapper"><i class="material-icons md-18 inline">mail</i>
<h6 class="inline">info#ex.com</h6>
</div>
wrap text and icon in one wrapper div. Set this wrapper div classname ```.wrapper````.(you can use any name for classname)
set .wrapper to display:flex;align-items:center.
<html>
<div class="wrapper">
<i class="material-icons md-18 inline">mail</i>
<h6 class="inline">info#ex.com</h6>
</div>
</html>
<style>
.wrapper{
display:flex;
align-items:center;
}
</style>
I could share working example but I need your code

issue with css - class not displayed

I ran into an issue I cannot reproduce on my local apache.
A class of my css is not taken into account by my html.
The positionTitleRec class is not accepted (e..g color is not displayed). Yet, when I'm putting the other class positionFrenchRec, the color is displayed properly
/* nanum-pen-script-regular - latin */
#font-face {
font-family: 'Nanum Pen Script';
font-style: normal;
font-weight: 400;
src: url('../fonts/nanum-pen-script-v15-latin-regular.eot');
/* IE9 Compat Modes */
src: local('Nanum Pen'), local('NanumPen'), url('fonts/nanum-pen-script-v15-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/nanum-pen-script-v15-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('fonts/nanum-pen-script-v15-latin-regular.woff') format('woff'), /* Modern Browsers */
url('fonts/nanumpenscript-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/nanum-pen-script-v15-latin-regular.svg#NanumPenScript') format('svg');
/* Legacy iOS */
}
#font-face {
font-family: 'Raleway Script';
font-style: normal;
font-weight: 400;
src: local('Raleway'), local('Raleway'), url('fonts/Raleway-SemiBold.ttf') format('truetype');
}
#font-face {
font-family: 'Montserrat Script';
font-style: normal;
font-weight: 400;
src: local('Montserrat'), local('Montserrat'), url('fonts/Montserrat-Regular.ttf') format('truetype');
}
.positiontitleRec {
position: absolute;
left: 5.1%;
right: 50.85%;
top: 3.64%;
bottom: 60.33%;
font-family: Montserrat Script;
font-style: normal;
font-weight: normal;
font-size: 60px;
line-height: 30px;
color: #E1C89B;
}
.positionFrenchRec {
position: absolute;
left: 5.1%;
right: 61.75%;
top: 10.7%;
bottom: 45.8%;
font-family: Raleway Script;
font-style: normal;
font-weight: normal;
font-size: 20px;
line-height: 30px;
color: #E1C89B;
}
<p class="positionTitleRec">
Bienvenue
</p>
<p class="positionFrenchRec">
<br>
<br>Yo soy Andy.
<br>
</p>
In your CSS, .positiontitleRec needs a capital T as classes are case-sensitive.

How do I use Material Icons Outline to a ::before element offline

I would like to know is it possible to use the outline type of the material fonts while they are downloaded locally to a ::before or ::after element? The closest I got is explained in this thread -
How to host material icons offline?
(you can scroll to the lower part of the thread or just simply press crtl+f and in the find window type "outline" and it will get you there - starting from the second result).
Here a dude named Wale explaines step by step how to use the outline type and indeed it works. I add an i-tag to the HTML with the class material-icons-outline, the icon is diplayed perfectly. However, when I try to do the same to a ::before element nothing is displayed. If anyone has an idea how this can be contemplate to work, a help will be much appreciated. Here are my HTML and CSS.
<div class="connected-house-links">
<ul>
<li class="material-icons">Енергетска Ефикасност</li>
<li class="material-icons">Безбедност и Сигурност</li>
<li class="material-icons-outline">Комфорт</li>
<li class="material-icons">Заштита на најмилите</li>
</ul>
</div>
//setting up to use both type of icons
#font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(MaterialIcons-Regular.eot); /* For IE6-8 */
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(MaterialIcons-Regular.woff2) format('woff2'),
url(MaterialIcons-Regular.woff) format('woff'),
url(MaterialIcons-Regular.ttf) format('truetype');
}
#font-face {
font-family: 'Material Icons Outline';
font-style: normal;
font-weight: 400;
src: url(Material-Icons-Outline.eot); /* For IE6-8 */
src: local('Material Icons'),
local('Material Icons-Outline'),
url(Material-Icons-Outline.woff2) format('woff2'),
url(Material-Icons-Outline.woff) format('woff'),
url(Material-Icons-Outline.ttf) format('truetype');
}
.material-icons-outline {
font-family: 'Material Icons Outline';
}
.material-icons {
font-family: 'Material Icons';
}
.material-icons-outlined,
.material-icons {
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
//using the desired fonts in css
.connected-house-links ul .material-icons:first-child::before {
content: '\e1a3';
font-weight: 100;
transform: scale(2);
position: absolute;
left: -2em;
bottom: -0.2em
}
.connected-house-links ul .material-icons:nth-child(2)::before {
content: '\e8e8';
transform: scale(2);
position: absolute;
left: -2em;
bottom: -0.2em
}
.connected-house-links ul .material-icons:nth-child(3)::before {
font-family: 'Material Icons Outline';
content: '\e88a';
transform: scale(2.3);
position: absolute;
left: -2em;
bottom: -0.1em
}
.connected-house-links ul li:last-child::before {
font-family: 'connected-home-icons';
content: '\e900';
transform: scale(1.7);
position: absolute;
left: -2em;
bottom: -0.1em
}

Self hosted google font not smooth in any browser

I got the "Lato" google font and want to self-host it (because of performance). I got it implemented and it looks shitty and not smooth in any browser, it looks really pixelated!
#font-face {
font-family: 'lato';
src: url('font/latoFont.eot');
src: url('font/latoFont.eot?#iefix') format('embedded-opentype'),
url('font/latoFont.ttf') format('truetype'),
url('font/latoFont.woff2') format('woff2'),
url('font/latoFont.woff') format('woff');
font-weight: 500;
font-style: normal;
}
html {
font-family: 'lato', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
font-size: 10px;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1.4rem;
color: #212121;
}
What can i do to get more satisfying and smooth results?
I usually use this hotfix
/*FIX FONT FOR GOOGLE CHROME ON WINDOWS*/
#media screen and (-webkit-min-device-pixel-ratio:0) {
#font-face {
font-family: 'MyFont';
src: url('fonts/myfont.svg#myfont') format('svg');
font-weight: normal;
font-style: normal;}
}
You can read more here

Can't figure out why the font for my logo isn't working

I'm trying to figure out why the font for my logo isn't downloading for other people. The font is called Aerokids.
The code in my CSS works fine for the other font type I have on my site. It's just the logo that's not working, even though it's done the same way. Does anyone have any ideas what might be wrong? Here is a screenshot of the fonts I have in the subfolder for my site:
Here is the GitHub URL for the site I'm working on.
#font-face {
font-family: 'Aerokids';
src: url('fonts/Aerokids.otf');
font-weight: normal;
font-style: normal;
font-family: 'odudo-semibold';
src: url('../fonts/odudo-semi-bold.eot');
src: url('../fonts/odudo-semi-bold.eot?#iefix') format('embedded-
opentype'),
url('../fonts/odudo-semi-bold.woff2') format('woff2'),
url('../fonts/odudo-semi-bold.woff') format('woff'),
url('../fonts/odudo-semi-bold.ttf') format('truetype'),
url('../fonts/odudo-semi-bold.svg#youworkforthem') format('svg');
font-weight: normal;
font-style: normal;
}
.logo {
font-family: 'Aerokids';
font-weight: normal;
color: #00E8FF;
font-size: 2.5em;
float: left;
width: 30%;
display: inline-block;
max-width: 100%;
height: auto;
vertical-align: middle;
margin: 0 auto;
}
You need to separate the two #font-face rules.
#font-face {
font-family: 'Aerokids';
src: url('fonts/Aerokids.otf');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'odudo-semibold';
src: url('../fonts/odudo-semi-bold.eot');
src: url('../fonts/odudo-semi-bold.eot?#iefix') format('embedded-
opentype'),
url('../fonts/odudo-semi-bold.woff2') format('woff2'),
url('../fonts/odudo-semi-bold.woff') format('woff'),
url('../fonts/odudo-semi-bold.ttf') format('truetype'),
url('../fonts/odudo-semi-bold.svg#youworkforthem') format('svg');
font-weight: normal;
font-style: normal;
}