Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 @font-face breaks Razor parser - can it remain inline via a workaround?

The CSS3 @font-face rule breaks a Razor section with the error message: CS0103: The name 'font' does not exist in the current context. It crashes at runtime.

It seems the CSS3 @ character is the problem that causes the Razor parser to fail.

Example:

@section HeadCustomStyleBlock {       <style type="text/css">           @font-face {               font-family: Gentium;             src: url(http://example.com/fonts/Gentium.ttf);                     }       <style>   }   

For context, the @section HeadCustomStyleBlock is being included in the Layout page's <head> element.

Instead of moving this to an external file, can I implement a workaround to keep it inline?

like image 461
John K Avatar asked Jul 14 '11 03:07

John K


People also ask

How do you stop Fouting?

The best way to deal with FOUT is to make the transition between the fallback font and web font smooth. To achieve that we need to: Choose a suitable fallback system font that matches the asynchronously loaded font as closely as possible. Adjust the font styles ( font-size , line-height , letter-spacing , etc.)

How do I use an OTF font in CSS?

Add a font-face section to your CSS code src: url('fonts/lovely_font. otf') format('opentype'); src: url('fonts/lovely_font. ttf') format('truetype'); As another optional efficiency measure, we can get the browser to check for a local copy of the font in case the user already has it.

What properties are in font face rule?

Parameter: The @font-face rule accepts four-parameter as described below: font-family: It specifies the font of an element. src: It is used to specify the location (URL) of the external resource ie., it holds the file path (url). font-stretch: It is used to set the text wider or narrower.


1 Answers

As per ScottGu's blog:

In cases where the content is valid as code as well (and you want to treat it as content), you can explicitly escape out @ characters by typing @@.

http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx

like image 174
Beno Avatar answered Nov 02 '22 15:11

Beno