Error with @media rule in <style> tag in .cshtml file
P粉769413355
P粉769413355 2023-08-16 18:37:05
0
2
518
<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>
P粉769413355
P粉769413355

reply all(2)
P粉502608799

try:

<style type="text/css">
    .on-the-fly-behavior {
    background-image: url('particular_ad.png'); 
}
@media screen and (max-width: 300px) { /* 添加screen and */
    .on-the-fly-behavior {
        background-image: url('particular_ad_small.png');
    }
}
</style>
P粉214176639

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:

<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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!