I have a blazor wasm application and I try to add a css file with css isolation. My File structure looks like this:
And my code in the Layout header is:
<Header Style="background: #fff; border-bottom: 1px solid #E5E5E5" Class="header-layout">
<div class="header-logo">
<img src="images/logo.png" alt="Logo" width="80" />
</div>
<div class="header-avatar">
<Avatar Style="background-color: #87d068" Icon="user" />
</div>
</Header>
And I have this Link in my index.html:
<link href="[Projectname].Client.styles.css" rel="stylesheet">
And the css code is:
.header-layout {
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
align-items: center
}
.header-logo {
flex-grow: 0
}
.header-avatar {
flex-shrink: 0
}
When I move the css to the app.css it is applied correctly. But when in the LayoutHeader.razor.css it doesn't do anything. The style.css is correctly resolved (or at least I don't see any errors on the console). Cache is disabled and I tried reloading everything.
The probelm was two fold:
For some reason you cannot have only a Blazor Component in a razor.cs file. That way the attribute cannot be applied. So you would have to surround it with a <div></div>
.
The header-layout
, header-logo
and header-avatar
need to have a ::deep
in front of it, since technically they are in a child component.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.