How to compile Fontawesome unique code with scss in css content - css

I just wanted to add font awesome unique code with key-value pairs but when I am trying to do that it's changing
Ex.
content: ;
SCSS code
$socialMediaIcons: (facebook: '\f09a', twitter: '\f099', linkedin: '\f0e1');
#each $key,
$value in $socialMediaIcons {
.#{$key} {
&::before {
font-family: fontAwesome;
content: #{$value};
}
}
}
CSS compile code
.facebook::before {
font-family: fontAwesome;
content: ;
}
.twitter::before {
font-family: fontAwesome;
content: ;
}
.linkedin::before {
font-family: fontAwesome;
content: ;
}

I've solved the problem in my ways. Here is the solution:
At first, download the font-awesome toolkit from their website or using npm or yarn. I've downloaded the free version.
And then import the fontawesome.scss brands.scss at the top of my scss file. You may import regular.scss or solid.scss files if you want to show those type of icons.
SCSS Code:
#import "../../fontawesome-free-5.10.2-web/scss/fontawesome.scss";
#import "../../fontawesome-free-5.10.2-web/scss/brands.scss";
$socialMediaIcons: (facebook: $fa-var-facebook, twitter: $fa-var-twitter, linkedin: $fa-var-linkedin);
#each $key,
$value in $socialMediaIcons {
.#{$key} {
&:before {
#extend %fa-icon;
#extend .fab;
content: fa-content(#{$value});
}
}
}
And don't forget to add font-awesome CSS file at the head of your .html file.
<link rel="stylesheet" href="fontawesome-free-5.10.2-web/css/all.min.css">

Related

How to remove unnecessary css when it compiled to output in TailwindCSS?

I'm combining tailwindcss with another ui framework (Ant Design), but having some conflicts with the css in tailwind.
I want to compile the necessary classnames if it is used to minimize conflicts
My expect example:
<div className="text-center font-bold" />
After compiled in output.css file:
.text-center {
text-align: center;
}
.font-bold {
font-weight: bold;
}
which this output results should not included css default like:
html{-moz-tab-size:4;-o-tab-size:4;tab-size:4;line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji}
.text-center {
text-align: center;
}
.font-bold {
font-weight: bold;
}
Just disable Preflight
// tailwind.config.js
module.exports = {
....
corePlugins: {
preflight: false,
}
}

WebEngineView: Set custom font to html content

How to apply custom font (font is in qrc) to some part of html content in WebEngineView?
I figured out how to use my custom font (but I'm not sure how safe is this):
Add custom font to qrc: ://res/font/myfont.ttf;
Create style.css in qrc with this content:
#font-face {
font-family: myfont;
src: url('qrc:/res/font/myfont.ttf');
font-weight: bold;
}
body {
font-family: 'myfont';
text-align: justify;
line-height: 25px;
}
In QML when content loaded to WebEngineView add your style.css to HTML:
WebEngineView {
id: webEngineView
onLoadingChanged: {
if (loadRequest.status == WebEngineView.LoadSucceededStatus) {
webEngineView.runJavaScript(
"var headHTML = document.documentElement.getElementsByTagName('head')[0].innerHTML;" +
"headHTML += '<link rel=\"stylesheet\" href=\"qrc:/css/styles.css\">';" +
"document.documentElement.getElementsByTagName('head')[0].innerHTML = headHTML;"
);
}
}
}
And last, run your app with this command line argument --disable-web-security

How to use #apply in a react component with css modules

I've got this in a global style.css:
:root {
--font: {
font-family: "Source Sans Pro", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
}
... and this in a react component's style.css:
.rightnav {
#apply --font;
float: right;
color: white;
}
In the component itself:
import React from "react"
import cssModules from "react-css-modules"
import style from "./style.css"
render() {
return (
<ul>
<li className={style.rightnav}>Blog</li>
</ul>
)
}
I get an error: No custom properties set declared for font.
You've got to import the global stylesheet into the local one. Because postcss-apply has no way to know about that global file while parsing the local one. So it's a good idea to have a partial with only custom properties and custom property sets declarations.
You probably want something like postcss-import
#import 'path/to/variables.css';
.rightnav {
#apply --font;
float: right;
color: white;
}

Is it possible to use Icons with css:before without hardcoding the code?

I am using the method answered here on StackOverflow to use custom police definition with other classes. This method is summarized below:
[class^="icon-"]:before,
[class*=" icon-"]:before {
font-family: FontAwesome;
}
.icon-custom:before {
content: "\f0c4";
}
When I'm using a custom class to use it, I have to use the code generated by the library:
i:after {
content: '\f0c4';
}
In case this code f0c4 change in the library, I would like to avoid reporting the change in every custom class one by one. I decided to use Sass or Less to be able to deal with this problem.
It would be like below but it does not work.
i:after {
.icon-custom
}
With Sass or Less, is it possible to avoid this magic number?
I know this will be possible:
i:after {
content: #custom-code-value
}
But I prefer to avoid changing the #custom-code-value: : "\f0c4";
Is it the only solution?
You can try to group all the content value in a map variable
I adapted for you an example
SCSS
// Map variable
$icons: (
facebook : "\f0c4",
twitter : "\f0c5",
googleplus : "\f0c6",
youtube : "\f0c7"
);
// Mixin doing the magic
#mixin icons-list($map) {
#each $icon-name, $icon in $map {
#if not map-has-key($map, $icon-name) {
#warn "'#{$icon-name}' is not a valid icon name";
}
#else {
&--#{$icon-name}::before {
content: $icon;
}
}
}
}
// How to use it
.social-link {
background-color: grey;
#include icons-list($icons);
}
CSS
// CSS Output
.social-link {
background-color: grey;
}
.social-link--facebook::before {
content: "";
}
.social-link--twitter::before {
content: "";
}
.social-link--googleplus::before {
content: "";
}
.social-link--youtube::before {
content: "";
}
So you only have to maintain that $icons variable in case some values change. hope you get the idea.

Compass Compile Converting "\f..." to "^O..."

When I run compass compile public/, compass converts the following styles:
.foundicon-rss:before {
content: "\f002";
}
.foundicon-facebook:before {
content: "\f003";
}
.foundicon-twitter:before {
content: "\f004";
}
... to this...
.foundicon-rss:before {
content: "^O002";
}
.foundicon-facebook:before {
content: "^O003";
}
.foundicon-twitter:before {
content: "^O004";
}
I'm viewing these fields via vim. It's messing up the styling of my site's icons. Is it a Foundation issue? Compass? Sass?

Resources