Error with @media rule in <style> tag in .cshtml file
P粉769413355
2023-08-16 18:37:05
<p>Why put the following code in the "style" tag</p>
<pre class="brush:php;toolbar:false;"><style type="text/css">
.on-the-fly-behavior {
background-image: url('particular_ad.png');
}
@media (max-width: 300px) {
.on-the-fly-behavior {
background-image: url('particular_ad_small.png');
}
}
</style></pre>
<p>When displayed in a "style" tag in a .cshtml file, an error is thrown: </p>
<pre class="brush:php;toolbar:false;">CS0103: The name 'media' does not exist in the current context</pre>
try:
In a .cshtml file, you cannot use it directly because it will be treated as a class or object. When you need to add content starting with
@
in an html file, you need to add an additional@
. Try using the following code: