FontAwesome 5 Unicode Support with inline font css - css

I am using a library which does not support a font-weight property but instead fontstyle is defined by font css property as explaned here
So I tested FontAwesome 5 with setting the fontstyle by font css property but it does not work. Am I doing something wrong or is FontAwesome 5 not supporting this mode of defining the fontstyle?
.calendar::before {
font-family: "Font Awesome 5 Free"; /* updated font-family */
font-weight: 400; /* regular style/weight */
content: "\f133";
}
.calendar2::before {
font: "400 Font Awesome 5 Free"; /* updated font-family */
content: "\f133";
}
<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet"/>
<div class="calendar"></div>
<div class="calendar2"></div>

This doesn't really have anything to do with FontAwesome.
When specifying font, you are required to include at least font-size (which must be a size in this situation, not initial, inherit, or unset) and font-family.
From MDN:
If font is specified as a shorthand for several font-related properties, then:
it must include values for:
<font-size>
<font-family>
it may optionally include values for:
<font-style>
<font-variant>
<font-weight>
<line-height>
font-style, font-variant and font-weight must precede font-size
font-variant may only specify the values defined in CSS 2.1, that is normal and small-caps
line-height must immediately follow font-size, preceded by "/", like this: "16px/3"
font-family must be the last value specified.
Also note that, if you do leave out optional values, the default normal is used in their place, overriding values set previously.
Try instead:
.calendar::before {
font-family: "Font Awesome 5 Free"; /* updated font-family */
font-weight: 400; /* regular style/weight */
content: "\f133";
}
.calendar2::before {
font: 400 16px "Font Awesome 5 Free"; /* updated font-family */
content: "\f133";
}
<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet"/>
<div class="calendar"></div>
<div class="calendar2"></div>

I see two errors:
font has 2 mandatory properties: size and family. You specified only family.
The text inside double quotes is a single value, so including 400 makes it part of the value, thus not a previous value.
Try something like this:
.calendar::before {
font-family: "Font Awesome 5 Free"; /* updated font-family */
font-weight: 400; /* regular style/weight */
content: "\f133";
}
.calendar2::before {
font: 400 1em "Font Awesome 5 Free"; /* updated font-family */
content: "\f133";
}
<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet"/>
<div class="calendar"></div>
<div class="calendar2"></div>

Related

Turning checkbox into Font Awesome checkbox with correct version [duplicate]

This question already has answers here:
Font Awesome 5, why is CSS content not showing?
(6 answers)
Font Awesome 5 shows empty square when using the JS+SVG version
(3 answers)
Closed 2 years ago.
I found a working version example with Font awesome 4.4.
However, once I tried to update it with the later version, say https://use.fontawesome.com/releases/v5.7.0/css/all.css it doesn't work any more.
I also checked the unicode e.g. this uncheckbox in the document has changed compare to the css code below?! https://fontawesome.com/icons/square?style=regular
To make myself more confused, the Font awesome document says "Updated: Version 5.10.2", I am not able to change to different version to check if checkbox icon has the same unicode.
<!--Working if I use 4.4 provided in example-->
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link href="style.css" rel="stylesheet" />
</head>
and
/*NOT working any more tested under version 5.7*/
.custom-fa input[type="checkbox"] {position:absolute;left:-999px;}
.custom-fa input[type="checkbox"]:focus + span{color:#46c0ef;}
.custom-fa label{cursor: pointer;}
.custom-fa label input[type="checkbox"] + span:before {
font-family: FontAwesome;
content: "\f096";
display: inline-block;
font-weight: 400;
font-style: normal;
font-size: 1.4em;
text-align:center;
letter-spacing: 6px;
}
.custom-fa label input[type="checkbox"]:checked + span:before { content: "\f046";letter-spacing: 3px; } /* checked icon */
.custom-fa label input[type="checkbox"]:indeterminate + span:before{content: "\f147";letter-spacing: 6px;}
Can someone please explain to me what is going on with different Font awesome versions and their unicodes?
How do I fix the code to work using the newer Font Awesome 5.7 or 5.10?

How to get black font weight from a Google font

Please go here end see Black font style. How do I get this style on my page. Here is what I've tried so far, but it's not working.
.title{
font-family:'montserrat' sans-serif;
font-weight:900;
font-weight:Black;
}
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<div class='title'>LOREM</div>
First, the font-family property requires values to be separated by a comma. Also, you should use the capital letter in the value.
Therefore, this…
font-family: 'montserrat' sans-serif;
…should be
font-family: 'Montserrat', sans-serif;
To add more weights to your font, use the customize menu:
Then, simply add the corresponding font-weight or font-style value:
font-weight: 900;
If you don't have that weight specified in your generated <link>, then the fallback family and weight will be used.
There are several variants based on which you can import the fonts. For Montserrat, there are Regular 400, Bold 700, Black 900 and many more. Just select the variant type and add that font, now you are good to go.
Based on your question the URL you need is
<link href="https://fonts.googleapis.com/css?family=Montserrat:900" rel="stylesheet">
First use 'Montserrat', sans-serif; (with ,)
Second font-weight:black; is invalid so remove it...
You can use font-style:normal
.title{
font-family:'Montserrat', sans-serif;
font-weight:900;
font-style:normal;
}
<link href="https://fonts.googleapis.com/css?family=Montserrat:900" rel="stylesheet">
<div class='title'>black</div>

Change font-family after font-awesome icon

I am builting a website using font-awesome icons and I noticed that the font-family changes when I use an icon.
I've read online about pseudo elements, but yet can't figure it out.
Is there any way (example of code), that I can use so as to inherit the same font-family which is used in the webiste, after using a font awesome icon?
Many thanks!
<script src="https://use.fontawesome.com/cce2885033.js"></script>
<br><i class="fa fa-check"> If the athlete does not have time and has to eat 1 hour before the game, 70g are usually enough.</i><br>
Font-Awesome applies its own font family. Use it like this:
<i class="fa fa-check"></i><p style="font-family:'yourfont';">TEXT</p>
OR use pseudo element ::before in css to apply font-awesome icon to the left(before) of your text without icon tag:
p::before {
font-family: "Font Awesome\ 5 Free";
display: inline-block;
padding-right: 3px;
font-weight: 900;
content: "\f00c";
}
You might do it setting several font names to font-family property:
i.fa {font-family: "FontAwesome", "Lobster", sans-serif}
<script src="https://use.fontawesome.com/cce2885033.js"></script>
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<br><i class="fa fa-check"> If the athlete does not have time and has to eat 1 hour before the game, 70g are usually enough.</i><br>

Font Awesome 5, why is CSS content not showing?

I am trying to use FontAwesome in the content of CSS.
It appears with the code for the icon instead of the icon. I have followed the online helps but still not working
css
#font-face {
font-family: 'FontAwesome';
src: url('https://use.fontawesome.com/releases/v5.0.6/css/all.css');
}
.fp-prev:before {
color:#fff;
content: '/f35a';
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
}
If you are using the JS+SVG version Read this: Font Awesome 5 shows empty square when using the JS+SVG version
First, you only need to include the CSS file of Font Awesome 5 either in the head tag using:
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
Or within the CSS file:
#import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css")
Then you need to correct the font-family and the content like below:
#import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css");
.fp-prev:before {
color:#000;
content: '\f35a'; /* You should use \ and not /*/
font-family: "Font Awesome 5 Free"; /* This is the correct font-family*/
font-style: normal;
font-weight: normal;
font-size:40px;
}
<i class="fp-prev"></i>
In some cases, you have to also add
font-weight:900
More detail here: Font Awesome 5 on pseudo elements shows square instead of icon
As a side note: Font Awesome 5 provide 4 different font-family for each pack of icons:
Font Awesome 5 Free for the free icons.
Font Awesome 5 Brands for the brand icons like Facebook, Twitter, etc.
#import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css");
.fp-prev:before {
color: #000;
content: "\f099";
font-family: "Font Awesome 5 Brands";
font-style: normal;
font-weight: normal;
text-decoration: inherit;
}
<i class="fp-prev"></i>
Font Awesome 5 Pro for the Font Awesome Pro.
Font Awesome 5 Duotone also included in the Pro package.
Related: Font Awesome 5 Choosing the correct font-family in pseudo-elements
Make your font-weight: 900;. I see you miss it
This is not showing because of color -issue . Please follow step :-
Step- 1. Copy this style in your page
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css">
Step- 2. copy this code at the top of your all.css in your page .
#import url("https://use.fontawesome.com/releases/v5.14.0/css/all.css");
Step- 3. Use the font-family and the content and color like
.password_invalid:before {
color: #ff0000;
content: '\f058'; /* You should use \ and not /*/
font-family: "Font Awesome 5 Free"; /* This is the correct font-family*/
position: relative;
margin-left: -36px;
padding-right: 13px;
font-weight: 400;
}
This Happened to me too. I had used this icon: as was using font awesome 5 cdn.
But when I tried to select the same class and then edit the icon, the css editing didn't run on the icon.
So the removed the "fas" from ".fas fa-plus-square" on the css selector and made it ".fa-plus-square{}".
So the CSS was like this (for me) : .fa-plus-square{
float: right;
} where i removed the "fas". And it worked for me.
where the Html class was <i class="fas fa-plus-square"></i>
And the cdn that I used: "https://use.fontawesome.com/releases/v5.0.7/css/all.css".
Hope this helps you
When you want to include FontAwesome the url you provided should be inside thehead tag as a stylesheet file:
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.6/css/all.css">
Then you can use Font Awesome as you have done.
I know I'm really late to answer this.
You have to include Fontawesome CSS in the header.
CDN -
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
If you have downloaded the source files then include as follows
<link rel="stylesheet" href="path-to-your-font-awesome-folder/css/all.min.css" />
Later you have to add the CSS as follows -
.fp-prev:before {
color:#000;
content: '\f35a'; /* replace / with \ */
font-family: "Font Awesome 5 Free"; /* here is the correct font-family */
font-style: normal;
font-weight: 900;
text-decoration: inherit;
}
if you wish to add it via <i> tag then you can follow
<i class="fas fa-arrow-alt-circle-right"></i>
Make sure your font weight is 900.
Refer - https://github.com/FortAwesome/Font-Awesome/issues/11946
An issue was raised in GitHub for the same. They have suggested that for the solid font awesome icons the font-weight should be 900.
Hope this will help you all.

Does the css rule font-family overwrite all of the inherited fonts or just adds more options?

I have this problem:
body{
font-family: 'MyFontFace-font', 'Lucida Grande', Tahoma, Verdana, Arial, etc.
}
H1 {
font-family: 'MyFontFace-font2'
}
And my question is: If the second font ('MyFontFace-font2') is not loaded, will H1 have the font inherited from body, or from default of browser?
Thanks a lot.
The default fallback fonts of the browser will be applied, and any setting on body is ignored.
When you assign a value to a property of an element, like font-family to h1 here, then inheritance will never apply to that property on that element (except, trivially, if you assign the value inherit and the browser supports that). This is not changed by casual things like the value specifying a nonexistent font.
I also tested this with the following simpler document (on a system that has no font named MyFontFace-font2 but has a font named Tahoma):
<!doctype html>
<title>Test5</title>
<style>
body{
font-family: Tahoma;
}
H1 {
font-family: 'MyFontFace-font2'
}
</style>
<h1>Hello world</h1>
In Chrome, Firefox, IE the result is that the browser’s default font is used, not Tahoma. This is the expected result, by the specifications.
If the rule on H1 is omitted, then Tahoma is used, due to inheritance – then the h1 element will inherit the font-family property from its parent.

Resources