Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify CSS @media within a razor file?

I have the following:

@if (Model.PageMeta.Sidebar == PageMetaSidebar.Small) { Html.RenderPartial("_SmallSidebar"); } 

and in my include file:

<style "text/css">     #sbr { width: 193px; }     #lft { left: 205px; top: 85px; right:  5px; bottom: 30px; }     #top { left: 215px; top: 85px; right: 15px; }     #btm { left: 215px; right: 15px; bottom: 30px; }     #mdl { left: 215px; top: 85px; right: 15px; bottom: 30px; }     @media print {         div#lft {left:10px; right: 10px; top: 0px;}         div#top {left:20px; right: 20px; top: 0px;}         div#btm {left:20px; right: 20px; }         div#mdl {left:20px; right: 20px; top: 0px;}     } } </style> 

However this gives me a compile type error:

_SmallSidebar.cshtml(7): error CS0103: The name 'media' does not exist in the current context 

Does anyone out there know how I could fix this so it accepts that @media is not something that needs to be evaluated?

like image 330
Janese Avatar asked Jul 29 '11 13:07

Janese


People also ask

How do you add a CSS to a razor page?

All you have to do is to place a style sheet in the Pages folder alongside the page that it is intended to affect. You just need to follow a specific naming convention, which is the Razor page file name with . css on the end. The bundled file itself is placed in the wwwroot folder when the application is published.

How can I use @media in CSS?

The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used.

What does @media do in SCSS?

The important purpose of @media directive is to set style rules for various kinds of media types and could be nested inside the SASS selector.

What does @media only screen mean in CSS?

CSS Syntax only: The only keyword prevents older browsers that do not support media queries with media features from applying the specified styles. It has no effect on modern browsers. and: The and keyword combines a media feature with a media type or other media features. They are all optional.


1 Answers

You can use @@ which razor ignores and prints one @.

like image 125
Buildstarted Avatar answered Oct 06 '22 12:10

Buildstarted