mamasi
mamasi

Reputation: 915

How to use static conf in CSS?

How to use static conf in CSS?

body {
        background: url('static/img/body.png');
        padding-top: 20px;
        padding-bottom: 40px;
        font-family: Georgia,"Bitstream Charter",serif;
      }

This not working.

My static conf:

STATIC_ROOT = '/home/user/domains/domain/public_html/website/website/static/'
STATIC_URL = '/home/user/domains/domain/public_html/website/website/static/'

Upvotes: 0

Views: 113

Answers (2)

Dan Hoerst
Dan Hoerst

Reputation: 6328

Paths inside of your CSS file are relative, so you don't need to set static at all in the CSS file.

For example:

Your stylesheet is located at /home/user/domains/domain/public_html/website/website/static/stylesheet.css

Assuming your file structure is:

-- /static
-- -- stylesheet.css
-- -- -- /img
-- -- -- -- body.png

You can simply define your body as:

body {
        background: url('img/body.png');
        padding-top: 20px;
        padding-bottom: 40px;
        font-family: Georgia,"Bitstream Charter",serif;
      }

And call your stylesheet in your HTML via:

<link rel="stylesheet" type="text/css" href="{{ STATIC_ROOT }}stylesheet.css">

Upvotes: 1

Wolph
Wolph

Reputation: 80111

Your STATIC_URL should be a url (i.e. static.yourdomain.com/your_application/ or similar), that looks like a path on your filesystem so it won't work.

Normally a relative url in your css files should work just fine.

And don't forget to run manage.py collectstatic: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#collectstatic

Upvotes: 0

Related Questions