4

I want to use my customs CSS located on the wwwroot/css/. in my BlazorControllers/Components/. files but nothing is loaded at execution. Is there something to specify in the client or in the lib project settings ?

My Library project is BlazorControllers and I use the component of the library in the Client project

enter image description here

4
  • 3
    1. Did you add <link rel="stylesheet" href="~/css/MyComponents.css" /> in your main page (e.g. _Host.cshtml) ? 2. Is that BlazorControllers project a Razor Class Library? Commented Jan 6, 2020 at 9:11
  • See this answer: stackoverflow.com/questions/51610513/… Commented Jan 6, 2020 at 9:15
  • 1
    @itminus it didn't work using ~/css/MyComponents.css but worked well with _content/BlazorControllers/css/MyComponents.css path. I don't know what's the difference between both. Commented Jan 6, 2020 at 13:53
  • 2
    _content is a pseudofolder configured to get the files from somewhere (by the StaticFiles middleware). Compare with _framework for the main js file at the bottom of Index.html . Commented Jan 6, 2020 at 14:09

1 Answer 1

8

In your Index.html (or _Host.cshtml) file, below the site.css line, add

<link href="_content/<YourLibrary>/styles.css" rel="stylesheet" />

where <YourLibrary> seems to be BlazorControllers in your case.

And when I read that picture right you (also) need

<link href="_content/BlazorControllers/css/MyComponents.css" rel="stylesheet" />
Sign up to request clarification or add additional context in comments.

1 Comment

I added a css library to indext.html (mine is client side app). But when I run the application I don't see the css link in the page source. Any idea? I checked the css file has build operation set to content, so isn't it supposed to be added?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.