asp.net mvc relative pathproblem - css

I used template in my asp.net mvc project. I copied all the template index file into _layout.cshtml
and after that I changed the path of the css file but its not working.
<!-- Template Stylesheet -->
<link href="../admin/dashmin-1.0.0/css/style.css" asp-append-version="true" rel="stylesheet">
it only works if change relative path to wwwroot/css/site.css
how can I fix this problem?

Related

Blazor WASM global style

I know I can use CSS isolation in components but I want to add a global file for general style.
I added a CSS file to the wwwroot, how can I link it to the project?
Adding a link tag to the index html didn't help.
I found the answer!
For everyone who might need it:
There a 3 steps:
Create a CSS file in the wwwroot under CSS folder.
Add tag in the index.html file for file CSS
<link href="css/{FILE-NAME}.css" rel="stylesheet" />
Add tag in the index.html file for solution CSS
<link href="{SOLUTION-NAME}.styles.css" rel="stylesheet" />

Custom .css file doesn't work with Thymeleaf & Spring MVC

So, I've spent like last hour trying to solve it, but I just can't get custom .css file to get linked with html files in Spring 5. I'm using Thymeleaf, Bootstrap & jQuery for frontend works. I'm using Intellij Community Edition.
My files hierarchy looks like this:
java
project_files
resources
static
css
main.css
templates
main.html
I have a line in main.html:
<link rel="stylesheet" type="text/css" th:href="#{/css/main.css}" href="../../css/main.css"/>
that should link my styles with the .html file. What can be wrong?
Try changing a little bit your folder structure, create a folder under resources called static, and a folder called css under static and place the css files there, something like:
🗁 resources
└─── 🗁 static
└─── 🗁 css
└─── main.css
Then you should be able to access it by using:
<link rel="stylesheet" type="text/css" th:href="#{/css/main.css}"/>

JSF and css don't work

I am using JSF 2.2 in a regular dynamic web project , i have included a css code in a xhtml page.
Web-content WEB-CONTENT Ressources css style.ss
in my index.xhtml i used this code
<link rel="stylesheet" href="WEB-INF/Ressources/css/style.css" type="text/css"/>
but the css doesn't work
Files inside WEB-INF aren't accessible from the outside. You have to place them in some other directory. For example:
<link rel="stylesheet"
href="#{request.contextPath}/Ressources/css/style.css" type="text/css"/>
I had the same problem.. If you are using maven or not sure where the css file is just open the war file with winzip and see what the css path is..

Angular css files not loading when controlling two Partials with a single Controller

I'm working on a web-application built upon the MEAN stack.
I use bootstrap as css lib, and have some css override in two files of mine "app.css" and "mio.css"
the app works just fine until I hit refresh in a controller that handles two partials, than everything gets reloaded except for my 2 css files.
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/mio.css">
If I inspect them they contain the index.html data (head body dcc)
could you suggest what's happening??
Try using full file paths to the css files. For example..
<link rel="stylesheet" href="/assets/css/app.css">
The issue might be on the server side. Since angular apps are single page ajax applications, the server has to redirect all requests to the index.html page EXCEPT for assets. Your server might be returning the index.html page instead of your css files.

In eclipse dynamic web project, how to link css to jsp file in webcontent folder

In Eclipse, I created a Dynamic Web Project and a JSP file under WebContent folder. I also created a CSS file under the WebContent folder. Then I use <link rel="stylesheet" type="text/css" href="XXX.css"> in the JSP to link to the CSS file but when I run on web server (Tomcat) the CSS didn't apply. Can someone tell me why?
You must put your web project name before the address path of your css file
Example:
<link rel="stylesheet" href="/YourProjectName/XXX.css" type="text/css">
or in more dynamic way:
<link rel="stylesheet" href="${pageContext.request.contextPath}/XXX.css" />
Have fun :)
You can use: With style.css file in WEB-INF/jsp folder
<style type="text/css">
<%#include file="css/style.css" %>
</style>
NOTE
This however copies the entire source of the CSS file into the HTML
output of the JSP page. In other words, this is a server-side include,
not a client-side resource reference. So you effectively miss the
advantage that the browser can cache static resources and this way you
end up with a bandwidth waste because the very same CSS file is
embedded in every single page. In other words, a bad idea in terms of
performance and efficiency.
as #BalusC described in comment! you want to test your style.css file anyway, this is a solution.
you can use
<link rel="stylesheet" type="text/css" href="path/css">
You should restart eclipse so that it maps all css and javascript files again.
I worked for me.

Resources