SASS #mixin compiling in .css file - css

Trying to understand why SASS is compiling wrong in CSS:
in _typography.scss I have:
#mixin fontType ($type) {
#if $type=="normal" {
#font-face {
font-family: "gotham";
font-weight: normal;
font-style: normal;
src: url("./assets/fonts/HomepageBaukasten-Book1/BOOK/WEB/HomepageBaukasten-Book.woff2");
}
} #else {
#font-face {
font-family: "gotham";
font-weight: bold;
font-style: normal;
src: url("./assets/fonts/HomepageBaukasten-Bold11/BOLD/WEB/HomepageBaukasten-Bold.woff2");
}
}
}
in main.scss:
#import "./abstracts/typography";
body {
#include fontType("normal");
background-color: $background-color;
line-height: 1.6;
}
and gets compiled in main.css file like so:
body {
background-color: #17141f;
line-height: 1.6;
}
#font-face {
body {
font-family: "gotham";
font-weight: normal;
font-style: normal;
src: url("/HomepageBaukasten-Book.1c60130f.woff2");
}
}
Any idea where the problem is? Am I going wrong somewhere?
TY

Like I said in the comments, the mixin works but you're using it inside a selector breaks it. Also just adding a font declaration to a class does not give that class the font. You have to use font-family to reference the font declaration.
Use it like this:
#import "./abstracts/typography";
#include fontType("normal");
body {
background-color: $background-color;
line-height: 1.6;
font-family: gotham;
font-weight: normal;
}
Overall there is not need to create a mixin for font declarations as the browser will not download fonts that have been declared until they are actually used. So you can happily do the below and it should all just work without loading too many fonts:
#font-face {
font-family: "gotham";
font-weight: normal;
font-style: normal;
src: url("./assets/fonts/HomepageBaukasten-Book1/BOOK/WEB/HomepageBaukasten-Book.woff2");
}
#font-face {
font-family: "gotham";
font-weight: bold;
font-style: normal;
src: url("./assets/fonts/HomepageBaukasten-Bold11/BOLD/WEB/HomepageBaukasten-Bold.woff2");
}
body {
background-color: $background-color;
line-height: 1.6;
font-family: gotham;
font-weight: normal; // this will use the "HomepageBaukasten-Book.woff2"
}
.some_other_selector {
font-family: gotham;
font-weight: bold; // this will use the "HomepageBaukasten-Bold.woff2"
}

Related

Why font-face doesn't work in my project?

I'm tryin' to change font-family in a laravel-mix project, but this code doesn't work.
Any help?
Thanks!!
#font-face {
font-family: Montserrat;
src: url(../font/Montserrat-Bold.ttf);
}
body {
font-family: Montserrat;
}
please try. do with ttc, not ttf. if don't have no ttf, then use online convert tool.
#font-face { font-family: yourFontName; font-weight: normal; src: url('./asset/fonts/meiryo.ttc') format('TTC'); } #font-face { font-family: yourFontName; font-weight: bold; src: url('./asset/fonts/meiryob.ttc') format('TTC'); } body{ font-family: yourFontName; font-size: 25px; }
please check this again. jhon sammie

How Include the font family (SFUIDisplay-Regular) in angular project?

we are trying to include the font-family SFUIDisplay-Regular we generate all the file formate like .eot,.otf, .svg, .ttf, .woff
these all file are import in my SCSS file but it's not work...
scss code are given below.
#import "./assets/fonts/SF_font/styles.css";
#font-face {
font-family: 'SFUIDisplay-Regular' !important;
src: url('./assets/fonts/SF_font/SFUIDisplay-Regular.ttf') format('embedded-opentype');
font-weight: normal;
font-style: normal;
}
body{
font-family: $fontFamily;
// letter-spacing: -1px;
background: $backgroundgray;
font-size: 14px;
color: $textcolor;
line-height: 16px;
padding-bottom:15px;
}

Custom font face doesn't load in web page

My file structure
diary:
diary.html
css
diary.css
sources
fonts
EmblemaOne-Regular.woff
My css code is:
#font-face {
font-family: 'EmblemaOne-Regular';
src: url('../sources/fonts/EmblemaOne-Regular.woff') format('woff');
}
body {
font-family: Verdana, Geneva, Arial, sans-serif;
font-size: small;
}
h1, h2 {
color: #cc6600;
text-decoration: underline;
}
h1 {
font-family: 'EmblemaOne-Regular', sans-serif;
font-size: 220%;
}
h2 {
font-size: 130%;
font-weight: normal;
}
blockquote {
font-style: italic;
}
The problem is, that this font didnt apply to my h1 title? Can someone explain, why?
Btw I tried to remove quotes, use double quotes, remove "format", use full internet path. Thank you in advance.

postcss-autoreset is overriding font-family with the browser's default

I'm using postcss-autoreset which applies all: initial; to any element I style in my CSS files.
But, when I try to set the font of the body element only elements that I haven't styled in CSS will get the font. Elements I have styled revert to the browser's default. Which is very odd.
all: initial; seems to be overriding font-face because when I view in Chrome inspector it's showing as overridden.
As an example below all my elements on the page are displaying with the Roboto font, except for text within header which is using the browsers default.
app.css
#import "variables.css";
#import "header.css";
#import "footer.css";
body {
font-family: 'Roboto';
margin: 0 auto;
display: block;
}
header.css
header {
padding: 10px 0;
}
config.js (PostCSS CLI config.js file)
{
"use": [
"postcss-import",
"postcss-cssnext",
"lost",
"rucksack-css",
"postcss-autoreset",
"postcss-font-magician"
],
"input": "src/app.css",
"output": "css/main.css",
"local-plugins": true,
"autoprefixer": {
"browsers": "last 2 versions"
}
}
Here is the output being produced by postcss:
#font-face {
font-family: Roboto;
font-style: italic;
font-weight: 100;
src: local("Roboto Thin Italic"),local(Roboto-ThinItalic),url(//fonts.gstatic.com/s/roboto/v15/12mE4jfMSBTmg-81EiS-YVQlYEbsez9cZjKsNMjLOwM.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/12mE4jfMSBTmg-81EiS-Yfk_vArhqVIZ0nv9q090hN8.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/12mE4jfMSBTmg-81EiS-YRsxEYwM7FgeyaSgU71cLG0.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: italic;
font-weight: 300;
src: local("Roboto Light Italic"),local(Roboto-LightItalic),url(//fonts.gstatic.com/s/roboto/v15/7m8l7TlFO-S3VkhHuR0at2fQcKutQXcIrRfyR5jdjY8.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/7m8l7TlFO-S3VkhHuR0at44P5ICox8Kq3LLUNMylGO4.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/7m8l7TlFO-S3VkhHuR0at4bN6UDyHWBl620a-IRfuBk.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: italic;
font-weight: 400;
src: local("Roboto Italic"),local(Roboto-Italic),url(//fonts.gstatic.com/s/roboto/v15/OiNnAEwKzzJkQCr4qZmeq_esZW2xOQ-xsNqO47m55DA.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/vPcynSL0qHq_6dX7lKVByfesZW2xOQ-xsNqO47m55DA.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/1pO9eUAp8pSF8VnRTP3xnvesZW2xOQ-xsNqO47m55DA.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: italic;
font-weight: 500;
src: local("Roboto Medium Italic"),local(Roboto-MediumItalic),url(//fonts.gstatic.com/s/roboto/v15/OLffGBTaF0XFOW1gnuHF0WfQcKutQXcIrRfyR5jdjY8.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/OLffGBTaF0XFOW1gnuHF0Y4P5ICox8Kq3LLUNMylGO4.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/OLffGBTaF0XFOW1gnuHF0YbN6UDyHWBl620a-IRfuBk.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: italic;
font-weight: 700;
src: local("Roboto Bold Italic"),local(Roboto-BoldItalic),url(//fonts.gstatic.com/s/roboto/v15/t6Nd4cfPRhZP44Q5QAjcC2fQcKutQXcIrRfyR5jdjY8.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/t6Nd4cfPRhZP44Q5QAjcC44P5ICox8Kq3LLUNMylGO4.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/t6Nd4cfPRhZP44Q5QAjcC4bN6UDyHWBl620a-IRfuBk.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: italic;
font-weight: 900;
src: local("Roboto Black Italic"),local(Roboto-BlackItalic),url(//fonts.gstatic.com/s/roboto/v15/bmC0pGMXrhphrZJmniIZpWfQcKutQXcIrRfyR5jdjY8.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/bmC0pGMXrhphrZJmniIZpY4P5ICox8Kq3LLUNMylGO4.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/bmC0pGMXrhphrZJmniIZpYbN6UDyHWBl620a-IRfuBk.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: normal;
font-weight: 100;
src: local("Roboto Thin"),local(Roboto-Thin),url(//fonts.gstatic.com/s/roboto/v15/PP2U5prMl9yvKSWVu6DtvPesZW2xOQ-xsNqO47m55DA.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/2tsd397wLxj96qwHyNIkxPesZW2xOQ-xsNqO47m55DA.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/vzIUHo9z-oJ4WgkpPOtg1_esZW2xOQ-xsNqO47m55DA.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: normal;
font-weight: 300;
src: local("Roboto Light"),local(Roboto-Light),url(//fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUffY6323mHUZFJMgTvxaG2iE.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfT8E0i7KZn-EPnyo3HZu7kw.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: normal;
font-weight: 400;
src: local(Roboto),local(Roboto-Regular),url(//fonts.gstatic.com/s/roboto/v15/5YB-ifwqHP20Yn46l_BDhA.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/2UX7WLTfW3W8TclTUvlFyQ.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: normal;
font-weight: 500;
src: local("Roboto Medium"),local(Roboto-Medium),url(//fonts.gstatic.com/s/roboto/v15/RxZJdnzeo3R5zSexge8UUfY6323mHUZFJMgTvxaG2iE.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/RxZJdnzeo3R5zSexge8UUVtXRa8TVwTICgirnJhmVJw.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/RxZJdnzeo3R5zSexge8UUT8E0i7KZn-EPnyo3HZu7kw.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: normal;
font-weight: 700;
src: local("Roboto Bold"),local(Roboto-Bold),url(//fonts.gstatic.com/s/roboto/v15/d-6IYplOFocCacKzxwXSOPY6323mHUZFJMgTvxaG2iE.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/d-6IYplOFocCacKzxwXSOFtXRa8TVwTICgirnJhmVJw.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/d-6IYplOFocCacKzxwXSOD8E0i7KZn-EPnyo3HZu7kw.woff) format("woff")
}
#font-face {
font-family: Roboto;
font-style: normal;
font-weight: 900;
src: local("Roboto Black"),local(Roboto-Black),url(//fonts.gstatic.com/s/roboto/v15/mnpfi9pxYH-Go5UiibESIvY6323mHUZFJMgTvxaG2iE.eot?#) format("eot"),url(//fonts.gstatic.com/s/roboto/v15/mnpfi9pxYH-Go5UiibESIltXRa8TVwTICgirnJhmVJw.woff2) format("woff2"),url(//fonts.gstatic.com/s/roboto/v15/mnpfi9pxYH-Go5UiibESIj8E0i7KZn-EPnyo3HZu7kw.woff) format("woff")
}
header,
header .brand,
header nav,
header nav li,
header nav a,
header nav,
header nav ul,
header nav li,
body,
body {
all: initial
}
header {
background: #00AFEC;
display: block
}
header .brand {
width: 100%
}
header nav li {
display: block;
text-align: center
}
header nav a {
color: #FFF;
text-decoration: none;
font-size: 18px
}
#media (min-width: 361px) {
header nav {
width: 100%
}
header nav ul {
float: right
}
header nav li {
padding: 0 30px
}
}
body {
font-family: 'Roboto';
margin: 0 auto;
display: block;
}
Any idea why this is happening?
postcss-autoreset accepts reset option. By default it is just all: initial, which resets font. But I recommend to set reset in all: initial; font-family: inherit; font-size: inherit.
So in postcss-autoreset you should explicit show what properties you really want to inherit. And you could set some inherit properties by default in reset option.
Normally the font-family is inherited by the parent element. So you may use a simple
html {
font-family: Roboto;
}
to make the whole page use the Roboto font, even though there is no font-family explicitly defined for your elements - they simply inherit the value from their parent which is html (or in your example body).
If you are using postcss-autoreset, all elements styled by you, will get the all: initial; property, which resets the font-family. Therefore these elements will NOT have the Roboto font-family.
Btw, I wouldn't recommend you to use postcss-autoreset. I simply don't see the point in using it, as it doesn't do much (only add 1 prop/value) and it kinda breaks the css inheritance concept with it. In my opinion people should use postcss primarily to balance browser-inconsistencies. Plugins like autoprefixer and postcss-fixes (yeah, some self-promotion here) do a great job. If you want to replace your preprocessor sass/less/stylus, some other plugins like precss might make sense, but this whole concept of adding many micro-plugins, leading to unexpected behavior and output, is IMHO too unstable and causes more problems than it solves.

Custom font is displayed weird

From the start I need to say that I know what I'm trying to do is not "the right way to do it", but the client I'm working for desperately wants THIS specific font.
So, I need to use on a client's website the exact font as VOGUE uses. So I took the .eot & .ttf and uploaded them on my server. Then I added the CSS definitions:
/*fonts fonts for IE*/
#font-face {
font-family: VogueDidot;
src: url('font/FBDidotL-Regular.eot') format('embedded-opentype');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "VogueDidot Light";
src: url('font/FBDidotL-Light.eot') format('embedded-opentype');
font-weight: normal;
font-style: normal;
}
/*fonts for other browsers*/
#font-face {
font-family: VogueDidot;
src: url('font/FBDidotL-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "VogueDidot Light";
src: url('font/FBDidotL-Light.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
And the CSS for my element is:
.post h1 {
display: block;
height: 100%;
font-family: VogueDidot;
font-size: 55px;
text-transform: uppercase;
overflow: hidden;
line-height: 58px;
}
And, normally, I expected to see everything working like a charm.
But it's not...
Here's how it should look like:
And that's how it looks on my website :
Any ideas?
Looks like the browser is trying to display the font bold and repeating the gray pixels (from the thin lines) next to each other. Try using font-weight: normal (The font-weight:bold is inherited from the h1 element).

Resources