Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdisamadMoh committed Mar 18, 2024
1 parent a6e8101 commit 0e3c010
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ We can add it from **nuget**, or directly referencing **BlazorStylesheet.dll**

Open `nuget` package manager in **visual studio** and paste the following code.

```csharp
Install-Package BlazorStylesheet -Version 1.0.0
```

1. After installation done, open the file **Program.cs** or **Startup.cs** or **MauiProgram.cs** in your blazor project.

**Add the following code**
Expand All @@ -42,7 +46,7 @@ Open `nuget` package manager in **visual studio** and paste the following code.

3. Now open **_Layout.cshtml** in **blazor server** which you can find it under **Shared** folder, or **index.html** in **blazor webassembly** and **MAUI** which you can find it under **wwwroot** folder.

**Add the following html tags in the <head>...</head> before any script or styles.**
**Add the following html tags in the head before any script or styles.**

```html
<link href="_content/BlazorStylesheet/fix.min.css" rel="stylesheet" />
Expand Down Expand Up @@ -77,7 +81,7 @@ Open `nuget` package manager in **visual studio** and paste the following code.

in our **MainLayout.razor**, let's inject the **main stylesheet** and call it `sheet`. Then we can use `sheet` property to write our CSS. You can do this in every component you want to access the **main stylesheet**.

Now copy the following code and paste in **MainLayout.razor**.
Now copy the following code and paste in **MainLayout.razor** C# code.

```csharp
[Inject]
Expand Down Expand Up @@ -169,7 +173,7 @@ Well, lets add a method and name it `Setup` and decorate it with `[StylesheetMet
[StylesheetMethod]
private void Setup()
{

}
```

Expand Down Expand Up @@ -270,8 +274,6 @@ Now build your application and refresh the browser. Your website body should be
>
> ![image](https://imgur.com/ZratGZV.png)


##### If everything is going right, let's write the CSS for our `Navbar.razor`

Although you can write your CSS in anyway you like, but it is good idea to categorize them in methods. That is what we will do here.
Expand Down Expand Up @@ -422,14 +424,10 @@ Here, I haven't covered a full tutorial on how to write CSS in C# using **Blazor

**Repository**: https://github.com/AbdisamadMoh/Stylesheet.NET


##### When and how to write CSS in components?

With **BlazorStylesheet**, we have the freedom to write our CSS anywhere in our Blazor project. This is handy for keeping styles specific to a particular component and updating our CSS in realtime. But remember, for bigger styles or styles used across your whole application, it's generally better to organize them in separate C# classes. This makes your code easier to manage.



Unlike classes, which we can access the **main stylesheet** through attribute decoration which the injection is managed by the **BlazorStylesheet** itself. In **components**, we can access the **main stylesheet** through injection provided by the **Dependency Injection (DI)** container provided by .NET.

In your components use `@Inject`. Put it top of your **razor** file.
Expand Down Expand Up @@ -458,8 +456,6 @@ In **components** or other places where **BlazorStylesheet** doesn't manage, you

> You don't need to call `StateHasChanged()` as that has no effect on **BlazorStylesheet**.



### Why we need...

#### `loading="loader"` attribute in our `<html loading="loader">` and `fix.css`?
Expand Down Expand Up @@ -490,8 +486,6 @@ Both solutions lies in `fix.css` file you added.

> **BlazorStylesheet** does not add any element to the DOM to create the loader. So you should not worry about your DOM being modified.



## More...

This library uses **Stylesheet.NET** which you can find the repository below
Expand Down

0 comments on commit 0e3c010

Please sign in to comment.