admin管理员组文章数量:1392068
I'm wondering if there is a way in a Blazor app to load a stylesheet using a conditional of some sort? I want to load different css according to a variable or user setting. Less about where the setting will come from, more about how to actually do this in app.razor
Such as:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
*** some conditional if here:
<link rel="stylesheet" href="condition1.min.css" />
*** else this
<link rel="stylesheet" href="condition2.min.css" />
< rest of links...>
<HeadOutlet />
</head>
<body>
<Routes />
blah blah
</body>
</html>
TYIA
I'm wondering if there is a way in a Blazor app to load a stylesheet using a conditional of some sort? I want to load different css according to a variable or user setting. Less about where the setting will come from, more about how to actually do this in app.razor
Such as:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
*** some conditional if here:
<link rel="stylesheet" href="condition1.min.css" />
*** else this
<link rel="stylesheet" href="condition2.min.css" />
< rest of links...>
<HeadOutlet />
</head>
<body>
<Routes />
blah blah
</body>
</html>
TYIA
Share Improve this question edited Mar 13 at 1:19 Zhi Lv 22k1 gold badge27 silver badges37 bronze badges asked Mar 11 at 19:09 MX313MX313 1651 silver badge10 bronze badges1 Answer
Reset to default 1You can treat app.razor just like any other razor component.
So you could just write
@if (SomeProperty)
{
<link rel="stylesheet" href="condition1.min.css" />
}
else
{
<link rel="stylesheet" href="condition2.min.css" />
}
and add the property below in a @code
segment:
@code
{
public bool SomeProperty { get; set; }
//...
}
本文标签:
版权声明:本文标题:c# - Use a directiveconditional to load different stylesheets in app.razor when starting Blazor app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744775312a2624586.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论