1

I have an external CSS stylesheet, but for some reason the images are not loading. Here is the source code at which i link to 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:

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.

14
  • Is the images folder in the same folder as the stylesheet? the code 'images/bg.jpg' will look for the images folder within the stylesheet folder. Try using absolute paths like - url(/images/bg.jpg); Commented Feb 3, 2012 at 11:39
  • 2
    Also, you have a grammatical error in your message about people being too dumb. Commented Feb 3, 2012 at 11:40
  • @SagarPatil They are all located in the same folder. So theres style.css, index.php, apply.php, and the images folder. Commented Feb 3, 2012 at 11:41
  • First test without the PHP code to see whether the problem relates to it. Then check e.g. with Firebug to see whether the style sheet file is even read by the browser. If problems remain, please post a URL or construct a fiddle that demonstrates the problem. Also specify which browser(s) you used for testing. Commented Feb 3, 2012 at 11:42
  • Right. So just use the absolute path - url(/images/bg.jpg). Commented Feb 3, 2012 at 11:42

5 Answers 5

1

Remember image url is relative to css file path and change path to background-image:url("images/bg.jpg")

Sign up to request clarification or add additional context in comments.

Comments

0

have you checked your path, that is correct or check the location of both files on same place

Comments

0

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.

Comments

0

Try this:

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

Comments

0

Let me offer a way to debug this particular issue and other CSS reference issues in the future. Open up your page and then activate your browser's developer tools. (CTRL+SHIFT+I in Chrome).

Go to the Elements tab. Navigate the DOM until you see the CSS Entry. The URL for the stylesheet will be a clickable hyperlink. 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.