我正在使用带有Django的Bootstrap,以及来自admin的css(用于日期小部件)。我的问题是,在我有日期小部件的页面上,admin css会覆盖bootstrap css,因此整个页面看起来不同。我该如何解决这个问题?
base.html文件
<head>
{% block extra_head %}
{% endblock %}
<link href="{{ STATIC_URL }}bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<link href="{{ STATIC_URL }}bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
</head>
带有日期小部件的模板
{% extends "base.html" %}
{% load adminmedia %}
{% block extra_head %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}admin/css/base.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}admin/css/widgets.css"/>
<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/core.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/admin/RelatedObjectLookups.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.init.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/actions.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/calendar.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/admin/DateTimeShortcuts.js"></script>
<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";</script>
{% endblock %}
答案 0 :(得分:1)
将引导程序css置于{% block extra_head %}{% endblock %}
内。不要担心,只要你没有调用{{block.super}}
,就不会激活bootstrap。
<head>
{% block extra_head %}
<link href="{{ STATIC_URL }}bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<link href="{{ STATIC_URL }}bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
{% endblock %}
</head>
要激活其他模板中的bootsrap,只需输入{{block.super}}
:
{% extends "base.html" %}
{% block extra_head %}
{{block.super}}
//other css here
{% endblock %}
更新:
覆盖admin现有的css。在你的bootstrap css中,你必须放置!important
以便它会强制你的模板遵循bootstrap设计
样品:
<p>This red text <strong style="color: red;">should be blue</strong></p>
<style>
strong { color: blue !important; }
</style>