首页 > 解决方案 > 对 CSS 的更改未显示在 404 页面上

问题描述

对 CSS 文件所做的更改不会应用于 404 错误页面

编辑:有问题的页面:https ://hinnahackers.no/404/

蝙蝠的权利:这不是相对路径问题。我在我的标题中指定一个基本的href,如下所示:

<base href="https://hinnahackers.no/">

我知道这行得通,因为我的 404 页面加载了我的 CSS 文件中的一些样式,但没有加载新添加的类。

这也不是强制刷新 CSS 文件问题,因为我已经在做 styles.css?v=X:

<link href="css/styles.css?v=749" rel="stylesheet" type="text/css" />

但它似乎不适用于我的 404 页面。不过,其他页面上的 CSS 也会更新,例如 index.php。

这是我的 .htaccess 文件,如果用户输入无效的 url,我会使用该文件将用户重定向到 404.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

#Rewrite everything to https
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#404 redirect
ErrorDocument 404 /404.php

在我的 CSS 中,我添加了以下类:

.404__heading {
    font-size: 2em;
    color: #fff;
    line-height: 1.5;
}

.404__error {
    margin-top: 50px;
    font-size: 2em;
    color: #ea0548;
    line-height: 1.5;
}

.404__entry__container {
    margin-top: 50px;
}

.404__entry__wrap {
    position: relative;
    display: inline-block;
    height: 20px;
    width: 21px;
    vertical-align: middle;
    margin-right: 12px;
}

.404__entry__wrap a {
    display: inline-block;
    vertical-align: middle;
    color: #fff;
    font-size: 2em;
    text-decoration: none;
}

.404__entry__top__dot {
    position: absolute;
    top: 0;
    left: 0;
    background: #ff6600;
    height: 7px;
    width: 7px;
}

.404__entry__middle__dot {
    position: absolute;
    top: 10px;
    left: 7px;
    background: #ff6600;
    height: 6px;
    width: 7px;
    transform: translateY(-50%);
}

.404__entry__bottom__dot {
    position: absolute;
    bottom: 0;
    left: 0;
    background: #ff6600;
    height: 7px;
    width: 7px;
}

.404__entry__caret {
    display: inline-block;
    vertical-align: middle;
    background: #fff;
    height: 35px;
    width: 18px;
    margin-bottom: -5px;
}

.404__heading::selection,
.404__error::selection,
.404__entry__wrap::selection,
.404__entry__wrap a::selection {
    text-shadow: none;
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
}

但他们没有在我的 404.php 页面上得到认可。所以现在我已经直接在我的 404 页面中添加了样式等。我对正在发生的事情完全不知所措。我已经在谷歌上搜索了几个小时,但找不到解决方案。

标签: css.htaccessredirecthttp-status-code-404

解决方案


CSS 类不能以数字开头。


推荐阅读