bsky
bsky

Reputation: 20222

Stylesheet contents not used

I have the following reference to my css stylesheet:

<link rel="stylesheet" type="text/css" href='@routes.Assets.versioned("stylesheets/main.css")' media="screen" />

The stylesheet is located at /public/stylesheets/main.css.

And has this content:

body {
   background-image: @routes.Assets.versioned("images/deer.jpg");
}

I'm not getting any errors, but no image appears in the background.

Am I doing something wrong?

Upvotes: 1

Views: 29

Answers (1)

Andriy Kuba
Andriy Kuba

Reputation: 8263

Public resources (assets) are not processing by the template engine, so

body {
   background-image: @routes.Assets.versioned("images/deer.jpg");
}

never processed.

Here is the similar question:

Can you reference images from css without using relative paths?

Solutions

  1. Use the static path

    body {
       background: url("/assets/images/deer.jpg");
    }
    

    The /assets part depends on your routes setting, /assets is a default.

  2. Write CSS in the template file, so it would be one that returns but your controller (not one in the public folder)

Upvotes: 2

Related Questions