简体   繁体   English

Asp.NetCore Blazor 使用 CSS

[英]Asp.NetCore Blazor Using CSS

I have done all of my coding in desktop so far.Now I am learning blazor.How does CSS classes work.I was under the impression that the classes were isolated within the component but it seems this is incorrect!到目前为止,我已经在桌面上完成了所有编码。现在我正在学习 blazor。CSS 类是如何工作的。我的印象是这些类在组件中是隔离的,但似乎这是不正确的!

Component 1.组件 1。

//Component One;
<h3 class="my-h3">One</h3>
<style>
   .my-h3{
       background-color:red;
   }
</style>

@code {

}

Component Two:组件二:

//component 2
 <h3 class="my-h3">Two</h3>
 <style>
    .my-h3{
        background-color:blue;
    }
 </style>
 @code {

 }

Index Page:索引页:

@page "/"
<One></One>
<Two></Two>
Welcome to your new app.

Both compents have a background of red.两个组件的背景都是红色的。 I thought that the classes would be self-contained but I guess not.我以为这些课程是独立的,但我想不是。 Is there a recognised way to deal with styling components?是否有公认的方法来处理样式组件?

I think you are looking for scoped styles. You can add this using a nuget package BlazorScopedCss.我认为您正在寻找作用域 styles。您可以使用 nuget package BlazorScopedCss 添加它。

Blazor Scoped Css Blazor 范围 Css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM