首页 > 解决方案 > Django- CSS 不适用于其他页面,例如标题标签

问题描述

我已将我的 css 文件链接到“main/static/css/style.css”中,并且我的页面位于“main/templates/main/pages.html”中。但是 CSS 不适用于某些页面,例如 h2 标签不采用样式。

base.html

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

隐私.html

{% extends 'main/base.html' %}

{% block content %}
<div class="main">
    <h1><b>Privacy</b></h1>
    <div style="height:35px" aria-hidden="true"></div>

    <div class="text_para">

        <h2 class="h2_privacy">Mission</h2>
        <p>paragraph<p> 
.......     

样式.css

.main {   
    -ms-flex: 70%; /* IE10 */
    flex: 70%;
    background-color: white;
    padding: 20px;
}

.text_para {
    margin-right: 5%;
    text-align: justify;
}

/*heading h2 for privacy page*/
.h2_privacy {
    color: black;
    font-family: 'Lucida Calligraphy', sans-serif;
}

标签: pythonhtmlcssdjango

解决方案


首先,您需要确保 CSS 加载正确(例如从浏览器开发工具的网络部分检查)。

其次,您需要确保元素在页面中并且具有正确的类匹配 CSS 文件。

如果您没有发现问题,请检查这两个并更新您的问题。


推荐阅读