You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Django项目中的CSS在Chrome浏览器正常生效?

Django页面Chrome浏览器CSS兼容问题

我是Python新手,正在学习Dave Gray的线上Django课程,课程中我们为导航功能编写了CSS样式。页面在Edge中显示完全正常,和视频示例效果一致,但Chrome会忽略部分CSS样式,显示效果不符。

编写的CSS代码

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    background-color: black;
    color: whitesmoke;
    font-size: 3rem;
    display: flex;
    flex-flow: column;
}

nav {
    padding: 1rem;
    background-color: #44B78B;
    color: white;
    font-size: 2.5rem;
}

main {
    flex-grow: 1;
    display: grid;
    place-content: center;
}

h1,
p {
    text-align: center;
}

a {
    text-decoration: none;
    color: #81dbb8;
}

a:hover {
    opacity: .85;
}

布局HTML代码

<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>
        {% block title %}
            Django App
        {% endblock %}
    </title>
    <link rel="stylesheet" href="{% static 'css/style.css' %}">
    <script src="{% static 'js/main.js' %}" defer></script>
</head>
<body>
    <nav>
        <a href="/">🏡</a> |
        <a href="/about">😊</a> |
        <a href="/posts">📰</a>
    </nav>
    <main>
        {% block content %}
        {% endblock %} 
     </main>
</body>
</html>

首页HTML代码

{% extends 'layout.html' %}

{% block title %}
    Home
{% endblock %}

{% block content %}
    <h1>Home</h1>
    <p>Check out my <a href="/about">About</a> page.</p>
{% endblock %}

请问如何让我的页面兼容Chrome浏览器?

显示效果对比

  • Edge正常显示:Edge正常显示效果
  • Chrome异常显示:Chrome异常显示效果

内容的提问来源于stack exchange,提问作者Corey Wilson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 20:25:10