FluentUI Blazor CSS #3687
-
In previous projects I have also used w3-CSS (e.g. class="w3-table-all w3-hoverable"). In my latest project I use FluentUI Blazor and would like to switch from w3-CSS to Fluent CSS to reduce the number of JS libraries in the project. But unfortunately I can't find a proper analogy in FluentUI Blazor, e.g. in Fluent-Accordion I find a class="heading", in Fluent-Button then class="button" and so on. I would have expected e.g. class="fluent-heading" analogous to w3-heading etc. How is CSS then implemented or assuming I would like to have my own HTML elements like FluentUI, which CSS classes do I use to realize this? Thanks Background to this question: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
We can only control the classes that we define ourselves. The
Thanks for the nice words. Can you remind me which issue you are referring to? We don't have anything like Fluent UI tables. Or ar you referring to the DataGrid? That component is using HTML tables now as well (since 4.11). |
Beta Was this translation helpful? Give feedback.
-
Ok, I have found an efficient way to control custom HTML elements via Fluent CSS properties. This is especially important if you store the Fluent design-properties as user settings (I have already written about this in detail here, how to change font size, font colors, control colors etc. in FluentUI via DI/CSS). As you have seen here, it does not work with Fluent that you have your own classes like with w3-CSS (because of Shadow-DOM). But you can still make it so that the settings that are changed via DI AccentBaseColor or DI NeutralBaseColor at runtime of the Blazor app also affect your own HTML elements. Here is how this works using the example of an HTML table:
Since this class is overwritten with the user settings in the MainLayout.razor (as I wrote about in detail at the beginning), this property was stronger, which results in the problem, because you set the fonts e.g. black and have a darker color with --accent-fill-rest, which then causes a very bad readable title (because black on a dark background). To solve this problem you can add the following class to w3.css, which overrides the set property, but only if you want to do this yourself by using this class.
In this way you can also use other CSS Fluent variables and adapt your own w3.css (or whatever the file should be called) accordingly with your own classes, which you then call in your own HTML elements. this gives you your own component, which appears with the same CSS properties as the rest of the Fluent elements (e.g. background color or font color). If you make Fluent Design dynamic (see my other post here), then you can change everything at runtime and the properties (e.g. colors) look the same both for your own HTML elements and for the Fluent components used in the app. pc |
Beta Was this translation helpful? Give feedback.
Ok, I have found an efficient way to control custom HTML elements via Fluent CSS properties. This is especially important if you store the Fluent design-properties as user settings (I have already written about this in detail here, how to change font size, font colors, control colors etc. in FluentUI via DI/CSS).
As you have seen here, it does not work with Fluent that you have your own classes like with w3-CSS (because of Shadow-DOM). But you can still make it so that the settings that are changed via DI AccentBaseColor or DI NeutralBaseColor at runtime of the Blazor app also affect your own HTML elements. Here is how this works using the example of an HTML table: