@media 媒体查询和 ASP.NET MVC razor 语法冲突 [英] @media media query and ASP.NET MVC razor syntax clash
问题描述
我有一个使用 Razor 视图引擎在 ASP.NET MVC 中运行的大型站点.
I've got a large site that runs in ASP.NET MVC using the Razor view engine.
我有一个基本样式表,其中包含整个站点的所有通用样式.但是,有时我会在页面的 <head>
中使用特定于页面的样式 - 通常是一两行.
I have a base stylesheet which contains all of the generic styling for the whole site. On occasion, however, I have page specific styles which in the <head>
of the page - usually this is one or 2 lines.
我不太喜欢将 CSS 放在 中,因为它不是严格的关注点分离,但是对于一两行,这确实是特定于该页面的,我不喜欢必须附加另一个文件并增加带宽.
I don't particularly like putting the CSS in <head>
as its not strictly separation of concerns, but for one or two lines, that really is specific to that page, I prefer not have to attach another file and add to the bandwidth.
我有一个实例,虽然我想将特定于页面的媒体查询放入 <head>
,但是因为媒体查询使用 @ 符号和方括号 {},所以它会发生冲突使用剃刀语法:
I've got an instance though where I would like to put a page specific media query into the <head>
, but because a media query uses the @ symbol and brackets {} it's clashing with the razor syntax:
@section cphPageHead{
<style>
/* PAGE SPECIFIC CSS */
...
@media only screen and (max-width : 960px) <-- the @ symbol here is clashing!
{
... }
}
</style>
}
有什么办法可以解决这个问题吗?
Is there a way I can get around this?
推荐答案
使用双 @@ 符号.这将转义@符号并在客户端正确呈现@media
use double @@ symbols. That will escape @ symbol and render @media correctly on client side
这篇关于@media 媒体查询和 ASP.NET MVC razor 语法冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!