我需要使用css将此主题应用于我的django模板。我编写了css文件,但我错了,并非所有样式都应用于模板。请帮忙。
这是包含theme.css和基本html的完整代码:
nav {
/* Repeating background image */
background: url(http://weebtutorials.com/wp-content/uploads/2012/11/a.png);
width: 210px;
margin: 20px;
}
nav ul {
/* Removes bullet points */
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
/* Any child positioned absolutely will be positioned relative to this */
position: relative;
}
nav a {
color: #e8e8e8;
padding: 12px 0px;
/* Fill all available horizontal space */
display: block;
/* Remove underline */
text-decoration: none;
/*
New CSS3 animations:
apply transition to background property, taking 1s to change it
*/
transition: background 1s;
-moz-transition: background 1s;
-webkit-transition: background 1s;
-o-transition: background 1s;
font-family: tahoma;
font-size: 13px;
text-transform: uppercase;
padding-left: 20px;
}
nav a:hover {
/*
RGBA background for transparancy:
last number(0.05) is the transparency
*/
background: RGBA(255, 255, 255, 0.05);
color: #fff;
}
nav a:hover span {
background: #7d2c41;
transform: rotate(90deg);
-moz-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
}
nav ul li:hover ul {
display: block;
}
nav ul ul {
position: absolute;
left: 210px;
top: 0;
border-top: 1px solid #e9e9e9;
display: none;
}
nav ul ul li {
width: 200px;
background: #f1f1f1;
border: 1px solid #e9e9e9;
border-top: 0;
}
nav ul ul li a {
color: #a8a8a8;
font-size: 12px;
text-transform: none;
}
nav ul ul li a:hover {
color: #929292;
}
nav span {
width: 12px;
height: 12px;
background: #fff;
display: inline-block;
float: left;
margin-top: 3px;
margin-right: 20px;
position: relative;
transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-webkit-transition: all 0.5s;
}
nav span:before {
content: "";
width: 12px;
height: 2px;
background: #3a3b3b;
position: absolute;
left: 0px;
top: 5px;
}
nav span:after {
content: "";
width: 2px;
height: 12px;
background: #3a3b3b;
position: absolute;
left: 5px;
position: top;
}
.cust-dropdown {
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 2px solid #fff;
position: absolute;
top: -120px;
right: 20px;
}
.cust-dropdown ul {
margin: -110;
padding-left: -145;
list-style: none;
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
<link href="{{STATIC_URL}}css/theme.css" rel="stylesheet">
</head>
<body>
<nav>
<ul>
<li class="current"><a href=""><span></span> Home </a></li>
<li> <a href=""><span></span>AI assisted backtesting </a>
</li>
<li> <a href=""><span></span>Best stocks to trade today </a></li>
<li> <a href=""><span></span>Get free data </a></li>
</ul>
</nav>
<div class="btn-group cust-dropdown pull-right">
<button type="button" class="btn btn-default dropdown-toggle cust-dropdown" data-toggle="dropdown" role="button">
<i class="glyphicon glyphicon-menu-hamburger"></i>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="{% url 'about' %}">About</a></li>
<li><a href="">Documentation</a></li>
<li><a href="">Pricing</a></li>
<li><a href="">Contact us</a></li>
<li><a href="">Register</a></li>
</ul>
</div>
</body>
</html>
答案 0 :(得分:0)
首先,您应该在 settings.py 文件中具备先决条件:
django.contrib.staticfiles
INSTALLED_APPS
您必须定义STATIC_URL
:
STATIC_URL = /static/
所有这一切,你都放入模板文件:
{% load static %}
<link href="{% static "css/theme.css" %}" rel="stylesheet">
有关详细信息,请参阅docs。