Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

use different font styles within a loaded font

Is there a way to use the different styles from a font that is loaded within a project? For example:

@font-face {
  font-family: WorkSans;
  font-style: normal;
  font-display: fallback;
  src: url(../sass/fonts/WorkSans.ttf) format("truetype");
}

.test{
 font-family: WorkSans;
 font-style: Regular;
}

.test2{
 font-family: WorkSans;
 font-style: Bold;
}

Is there a way I can use regular, bold, extrabold etc., from a font that’s loaded into a project or do I have to load in the exact style for each?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’ll need to define a @font-face rule for every style. You can define them as below:

/* Regular font */
@font-face {
  font-family: WorkSans;
  font-style: normal;
  font-display: fallback;
  src: url("../sass/fonts/WorkSans.ttf").format("truetype");
}

/* Bold font */
@font-face {
  font-family: WorkSans;
  font-style: normal;
  font-weight: 700;
  font-display: fallback;
  src: url("../sass/fonts/WorkSans-Bold.ttf").format("truetype");
}

/* Extra Bold font */
@font-face {
  font-family: WorkSans;
  font-style: normal;
  font-weight: 800;
  font-display: fallback;
  src: url("../sass/fonts/WorkSans-ExtraBold.ttf").format("truetype");
}

.test {
  font-family: "WorkSans";
  font-weight: 400;
}

.test2 {
  font-family: "WorkSans";
  font-weight: 700;
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading