According to the V25 documentation the styles.css file should be located as follows…
Stylesheets, placed in the src/main/resources/META-INF/resources folder, are loaded with the @StyleSheet annotation.
Is this correct? The styles.css file I place into this folder does not seem to work. I am trying to colour a row in a Grid component per the Grid component Styling instructions for " Dynamically Styling Rows & Columns" and my css instructions seem to be ignored.
Here’s my code for the AppShell…
@StyleSheet(Aura.STYLESHEET) @StyleSheet(“styles.css”)
public class AppShellITSiMonitor implements AppShellConfigurator {
I’m not sure, but there might be an issue in the new Aura theme that prevents overriding background-color, as it uses background-image to apply the cell color. You could try background instead, and see if that helpes.
That possible issue should not affect text-align however, so if that also is not working, then we’re probably looking at something else.
Can you check if any other styles are getting applied?
I switched the CSS as you suggested and included the additional css for “right2” and neither change affected the output. I also removed the text-align and tried text-align: center. I also stopped the application did a full clean and compile to make sure there wasn’t anything that was preventing a live reload of the styles.css file.
So the path to the styles.css is definitely `src/main/resources/META-INF/resources’?
Could you apply some static styles in your css to see if those get applied?
E.g. if you have some buttons somewhere you could try adding this to styles.css and see if that has any effect:
vaadin-button {
background: red !important;
}
That makes it a lot easier to pinpoint the problem without also having to consider the possibility of those part names not getting dynamically applied as they should, and the difficulty of checking part names applied to a Grid cell with browser dev tools.
BTW, trying to drill down into the elements with the browser tools is quite painful and doing so crashes Firefox on Debian. It doesn’t crash Chromium on Debian though. I can see the “cell_not_connected_right” on the cell when I drill down into the cell that should be coloured.
Did you check the browser network tab to see if there’s the HTTP request that loads the stylesheet?
Are you deploying your application as a WAR file? Which servlet container?
Maybe the servlet container is not serving resources from META-INF/resources.
If you are packaging the WAR with Maven, try to move the stylesheet in src/main/webapp (How to load resources dynamically in Vaadin).
Sorry. I should have read the page you referred to first but I just moved my files to that location, did a clean and rebuild of the war file and still no CSS is being applied.
But is the resource served? What happens if you access it directly from the browser (e.g. http://localhost:8080/styles.css)? Can you see the contents? or do you get a 404 response? Or something else?
That’s right, I think. So the app is running from Tomcat webapps/MyApp and when I access my app via the browser I’m using http://localhost:8080/MyApp.
My Servlet looks like this…
@WebServlet(urlPatterns = “/*”, name = “MyApp”, asyncSupported = true, initParams = { @WebInitParam(name = “heartbeatInterval”, value = “30”), // was 30 @WebInitParam(name = “closeIdleSessions”, value = “false”)}) // was false
public class ServletITSiMonitor extends VaadinServlet
If you can see the resource at http://localhost:8080/MyApp/styles.css and if you confirm that it is loaded correctly also when you open your Vaadin view (looking for it in the browser network tools), then I have no idea why the styles are not applied.
So I just moved my styles.css file into src/main/webapp/MyApp and it applied the CSS tags.
Thank you!!
Actually I now see it was my fault. Trying to get to the bottom of the problem I changed the path to my @StyleSheet to “MyApp/styles.css” Removing the “MyApp” part let it load from the proper src/main/webapp folder.
@marcoc_753, should we add some guidance to docs for others with a similar setup?
(I’m afraid my knowhow of different servlet configs etc is woefully inadequate for it…)