使用 ASP.NET 核心 css 隔离时目标 body 标记

Target body tag when using ASP.NET Core css isolation

我在 RazorPages 中使用“css 隔离”。

我有一个 _Layout.cshtml_Layout.cshtml.css。我想为 body 应用背景色。所以我尝试了 body { background-color: red }.

但这会生成具有隔离属性的 css,例如html body[b-d29f2jaemq] { background-color: red); }htmlbody 标签没有这样的属性。

有没有办法在 css 隔离文件中定位 body 标记?

But that generates css with an isolation attribute, e.g. html body[b-d29f2jaemq] { background-color: red); }. The html and body tags don't have such attributes.

Is there a way to target the body tag in a css isolation file?

我可以重现这个问题,这可能是一个错误或设计,我建议你可以post这个问题到Asp.net Core Github forum,然后开发团队会帮助检查它。

作为临时解决方法,您可以尝试将 body { background-color: red } 添加到 wwwroot 文件夹中的 site.css 文件,并在布局页面中添加此文件引用:

<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />