Home > other >  Target body tag when using ASP.NET Core css isolation
Target body tag when using ASP.NET Core css isolation

Time:05-09

I'm using "css isolation" with RazorPages.

I have a _Layout.cshtml and _Layout.cshtml.css. I want to apply a background color to the body. So I tried body { background-color: red }.

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?

CodePudding user response:

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?

I could reproduce the problem, this might be a bug, I suggest you could post this question to the Asp.net Core Github forum, then, the developer team will help to check it.

As a temporary workaround, you can try adding body { background-color: red } to the site.css file in the wwwroot folder, and add this file reference in the layout page:

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