0

I want to split my CSS into multiple files to match with each template and app. But the following problem keeps me baffled. In the base.css of my base.html template, I have an element class button declared as following:

.button {
  ...
}

So, all buttons should follow this css. In an app called table, in a template table_view.html that extends base.html

{% extends "base.html" %}
{% load static %}

{% block content %}
<link href="{% static 'css/table.css' %}" rel="stylesheet" />
...
     <button class="btn-avail table">Table</button>
...
{% endblock %}  

I have a different format for class btn-avail in table.css. But I could not get it to load and override the base format. If I change the class name to button (of base.css), it reflects the base format. Or if I place btn-avail in the base.css, then its format is correctly reflected.

In my settings.py, here is my static directory:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

What am I doing wrong? Thanks. Update: here is the folder structure for app table table/static/css/table.css. And the base.css sits here: project_root/static/css.

0

1 Answer 1

1

The CSS snippet you've posted applies to any element with a class of 'button' - the button element you've defined in the template does not have that class.

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

3 Comments

I guess my question is why doesn't it load the table.css. I think I may miss something in settings?
That stylesheet is not getting loaded at all? Can you share a snippet of the rendered HTML?
OK, I found out why: something about "caching". I have to refresh the page with Ctrl+F5. I think my settings and folder structure is correct. Thanks. Closing this.

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.