gpt4 book ai didi

css - .cshtml 文件中 <style> 标记中的 @media 规则引发错误

转载 作者:行者123 更新时间:2023-12-04 16:09:42 34 4
gpt4 key购买 nike

为什么要放在下面一行

<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>

.cshtml 文件中的“style”标签在浏览器中显示时抛出错误:

CS0103: The name 'media' does not exist in the current context

最佳答案

在 .cshtml 中,您不能按原样使用它,因为它将被视为类或对象。每当您需要在 html 文件中添加以 @ 开头的任何内容时,都需要添加一个额外的 @。试试这个

<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>

关于css - .cshtml 文件中 &lt;style&gt; 标记中的 @media 规则引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32133673/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com