链接文件中的某些CSS语句有效

时间:2018-06-21 03:16:30

标签: css css3 django-templates css-selectors

我有以下html:

{% extends 'core/base.html' %}
{% load static %}


{% block head %}
    <link rel="stylesheet" type="text/css" href="{% static 'core/css/index.css' %}">

    <title>OBs Lawn Care</title>
{% endblock %}

{% block body %}

    <!-- background image-->
    <img src="{% static "core/images/lawn.jpg" %}" alt="My image"/>

    <!-- navigation bar-->
    <ul id="nav">
        <li><a id="nav_logo" href="#">LOGO</a></li>
        <li><a href="#" class="nav_item">fff</a></li>
        <li><a href="#" class="nav_item">Services</a></li>
    </ul>

    <h1>COMPANY NAME</h1>
{% endblock %}

和index.css:

img{
    position: fixed;
    top:0;
    left:0;
    width: 100%;
    height: 40%;
    z-index:-2;
}

#nav{
    z-index:-1;
    width: 100%;
    position: fixed;
    top: 7%;
}

#nav li{
    display:inline;
}

#nav a{
    color:black;
}
h1{
color:blue;
}

所有img样式都可以正常工作,但是h1#nav a的颜色不会更改为默认值。 (请注意,我尝试使用<h1 style="color: blue">COMPANY NAME</h1>直接在html中进行样式设置,并且该方法起作用了,因此,我相信它必须与css文件一起使用)。感谢您的任何帮助。

1 个答案:

答案 0 :(得分:0)

语法还差一点,亲! :)这应该可行,下面是一个小提琴http://jsfiddle.net/bD9nC/32/

的示例
#nav{
    z-index:-1;
    width: 100%;
    position: fixed;
    top: 7%;
}

ul#nav{
    display:inline;
}

a#nav{
    color:black;
}