question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested @font-face results in invalid syntax

See original GitHub issue

Input:

.foo {
  @font-face {
   font-family: "Ionicons";
   src:url("../fonts/ionicons.eot?v=1.4.0");
   src:url("../fonts/ionicons.eot?v=1.4.0#iefix") format("embedded-opentype"),
    url("../fonts/ionicons.ttf?v=1.4.0") format("truetype"),
    url("../fonts/ionicons.woff?v=1.4.0") format("woff"),
    url("../fonts/ionicons.svg?v=1.4.0#Ionicons") format("svg");
   font-weight: normal;
   font-style: normal;
  }
}

Result:

@font-face {
  .foo {
    font-family: "Ionicons";
    src: url("../fonts/ionicons.eot?v=1.4.0");
    src: url("../fonts/ionicons.eot?v=1.4.0#iefix") format("embedded-opentype"), url("../fonts/ionicons.ttf?v=1.4.0") format("truetype"), url("../fonts/ionicons.woff?v=1.4.0") format("woff"), url("../fonts/ionicons.svg?v=1.4.0#Ionicons") format("svg");
    font-weight: normal;
    font-style: normal; } }

Could I put the font-face outside? Certainly, but what I am attempting here to wrap an entire stylesheet (imports and all) in an outer selector, to provide a stylesheet for an embeddable widget that must not clobber any other styles on the page. I can move fonts outside the top-level selector, but it does make my stylesheets more awkward, and I have to break them up more.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:7
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
desercommented, Jun 12, 2017

I’d kind of prefer to just leave the behavior as-is.

Hi Guys, this is abnormal behavior. Sometimes it’s impossible to wrap directives into @at-root. Example: I’m using font-awesome and want to restrict it by wrapping into higher order css class to prevent css class name collisions ( I need to embed my site into another one where the same libraries could be used with different overrides).

7reactions
apfelboxcommented, May 19, 2014

Does this work for you?

.foo {
  @at-root {
    @font-face {
     font-family: "Ionicons";
     src:url("../fonts/ionicons.eot?v=1.4.0");
     src:url("../fonts/ionicons.eot?v=1.4.0#iefix") format("embedded-opentype"),
      url("../fonts/ionicons.ttf?v=1.4.0") format("truetype"),
      url("../fonts/ionicons.woff?v=1.4.0") format("woff"),
      url("../fonts/ionicons.svg?v=1.4.0#Ionicons") format("svg");
     font-weight: normal;
     font-style: normal;
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass – Nested @font-face results in invalid syntax | UIthought
Just wanted to share one issue which I have faced recently with my current angular-cli project. Basically, issue related to the @font-face ......
Read more >
Python: Nested if SyntaxError: invalid syntax - Stack Overflow
Generally, if you get syntax errors when your code is valid, it's either due to the line above or due to bad indentation....
Read more >
font-family - CSS: Cascading Style Sheets - MDN Web Docs
The font-family CSS property specifies a prioritized list of one or more font ... Syntax. /* A font family name and a generic...
Read more >
Using with Preprocessors - Tailwind CSS
By default, it uses the postcss-nested plugin under the hood, which uses a Sass-like syntax and is the plugin that powers nesting support...
Read more >
mjml-guides – Documentation for MJML - The Responsive ...
Get your speed and productivity boosted with MJML's semantic syntax. Say goodbye to endless HTML table nesting or email client specific CSS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found