Setting Background with Vaadin
When using Spring Boot with Vaadin, place the background image in the src/main/resources/static
folder. If not using Spring Boot, then use the src/main/webapp
folder for the background image.
Add the necessary CSS to customize the background. By default, the Valo style will apply a background color to the div with the class v-ui
. You can create a custom theme to override the background through that, or update the style directly in the code.
@SpringUI
public class MyUi extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
initBackground();
initContent();
}
private void initBackground() {
Page.getCurrent().getStyles().add(
".v-ui { background: url(background.jpg) no-repeat center center fixed;" +
"-webkit-background-size: cover;" +
"-moz-background-size: cover;" +
"-o-background-size: cover;" +
"background-size: cover; }"
);
}
...
CSS Customization
To learn more about customizing CSS for background images, you can refer to resources like CSS-Tricks or other sources. The best solution will depend on how you want the background image to behave.