简体   繁体   English

CSS样式表不起作用

[英]CSS Stylesheet not Working

I have an external CSS stylesheet, but for some reason the images are not loading. 我有一个外部CSS样式表,但是由于某些原因,图像无法加载。 Here is the source code at which i link to style.css . 这是我链接到style.css的源代码。

<?
        session_start();
        if(isset($_POST['submit'])){
                if(!isset($_POST['rules'])){
                        $error = "Must read rules at spawn.";
                } else if(isset($_POST['grief'])){
                        $error = "We don't normally allow griefers. Your not allowed on our server unless you ask an Admin.";
                        $_SESSION['banned']=true;
                } else if(!isset($_POST['reg'])){
                        $error = "We prefer regular players.";
                } else if(empty($_POST['username'])){
                        $error = "The username field is empty?.";
                } else if($_POST['dumbtest'] != "6"){
                        $error = "Your too dumb to join this server.";
                } else {
                        include "comms.php";
                        addPlayerToExplorer($_POST['username']);
                        $error = "Welcome to SurviveEquestria, if everything went OK your now a Builder!";
                }
        }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>| Home</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

And theres nothing special about the style.css, but it begins with: 而且style.css没什么特别的,但它始于:

body {
background-image:url(images/bg.jpg);
}

#container {
margin-left:auto;
margin-right:auto;
width:1000px;
}

All of my images are located in an images folder, so i believe it points to the right images. 我所有的图像都位于图像文件夹中,因此我认为它指向正确的图像。

记住图像URL相对于css文件路径,并将路径更改为background-image:url(“ images / bg.jpg”)

Let me offer a way to debug this particular issue and other CSS reference issues in the future. 让我提供一种在将来调试此特定问题和其他CSS参考问题的方法。 Open up your page and then activate your browser's developer tools. 打开页面,然后激活浏览器的开发人员工具。 (CTRL+SHIFT+I in Chrome). (Chrome中的CTRL + SHIFT + I)。

Go to the Elements tab. 转到元素选项卡。 Navigate the DOM until you see the CSS Entry. 浏览DOM,直到看到CSS条目。 The URL for the stylesheet will be a clickable hyperlink. 样式表的URL将是可单击的超链接。 Click it. 点击它。 See where the browser navigates you. 查看浏览器在哪里导航。 this should give you an indication as to what the fix is. 这应该为您提供有关修补程序的指示。 Maybe you are too deep in the folder structure, maybe you are too shallow. 也许您对文件夹结构的了解太深,也许您太浅了。 In any case, I solve 99% of my CSS reference issues this way. 无论如何,我都是通过这种方式解决了99%的CSS参考问题。

尝试这个:

background: url(../images/bg.jpg)

您是否检查过路径正确或在同一位置检查了两个文件的位置

Since you comment that “everything works fine when its not live (on my computer), but when i upload it to my host, it doesn't work any more”, the problem is apparently in the process of uploading (maybe transferred the image in a wrong mode) or in the server-side settings. 由于您评论说“一切正常(当不在我的计算机上时一切正常,但是当我将其上传到主机时,它不再起作用了”),问题显然出在上传过程中(也许传输了图像(在错误的模式下)或在服务器端设置中。 There's not much more we can do to help you without any relevant information about server-side things. 如果没有服务器端内容的任何相关信息,我们可以为您提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM