0

Hi, I have an html(footer) file and a css(webflow) file. But I can't use my css file.

This my conf class

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler(
                        "/webjars/**",
                        "/img/**",
                        "/css/**",
                        "/js/**")
                .addResourceLocations(
                        "classpath:/META-INF/resources/webjars/",
                        "classpath:/static/img/",
                        "classpath:/static/css/",
                        "classpath:/static/js/");
    }

}

CSS not showing/not working

enter image description here

The file named webflow.css does not work on footer.html

<head>
  <link rel="stylesheet" th:href="@{../static/css/webflow.css}" media="screen" href="../static/css/webflow.css" type="text/css"/>
</head>

I use th:href label but it's not working. How can i resolve this problem?

frankly, I'm not sure if I've given the addResourceHandler the parameters correctly, but I've tried many different parameters

  • try this, ``. Also, in addResourceLocations, make classpath:/static the root (.addResourceLocations("classpath:/static/") ) – dsp_user Jan 12 '23 at 14:20
  • thank you for your answer but both methods didn't work – emiirhaneksi Jan 12 '23 at 14:31
  • have you implemented any security that we should know about? – dsp_user Jan 12 '23 at 14:32
  • could you try referring to [this](https://stackoverflow.com/a/29475520/10671013) or [this](https://stackoverflow.com/a/51083565/10671013)? Although it is not for css file, it is for image in the resources folder, so I am thinking the relative path used can be extrapolated and applied in your situation. – Tan Yu Hau Sean Jan 12 '23 at 14:44
  • first of all thank you for your answer. I tried both but don't work. – emiirhaneksi Jan 12 '23 at 21:04

1 Answers1

0

Try th:href="@{/css/webflow.css}" instead of th:href="@{../static/css/webflow.css}". It worked for me

timofeevle
  • 54
  • 3