5

I have a css file and i want to import another css file inside it. How can I do this in Django ?

This is my style.css file and I want to import owl.carousel.css in it.

@import url("owl.carousel.css");

body {
    margin: 0;
    padding: 0;
    color: #34495E;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 14px;
    line-height: 21px;
    position: relative;
    background: #fff;
}

I am using {% load static %} on my template to link style.css but how can import a css inside a css ?

<link href="{% static "assets/css/style.css" %}" rel="stylesheet"> 

2 Answers 2

6

If you want to import a .css file inside a .css you will need to use the path, as usual.

@import url('/path/to/your/file.css')

If they are in static folder:

static/styles/file1.css
static/styles/file2.css

/* in file2.css */
@import url('file1.css')

It is not possible to use the django template language inside a .css file.

Sign up to request clarification or add additional context in comments.

1 Comment

It looks like you can use the django templates in any file: stackoverflow.com/a/55225412/6655092
0

You can also use HTML style and script tags to load something inside your static files.

<style>
    @import url("{% static 'path/to/your/file.css')")
</style>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.