-2

My internal css is this one:

   <style type="text/css">
       .OneClass
       {  
          background: url(/Images/star.png) no-repeat !important;
       }
    </style>

OneClass is name of a class attribute in one div in td tag.

When I'm writing in external css file:

.OneClass
{  
     background: url(/Images/star.png) no-repeat !important;
}

it's not working. Why?

This is how I include the css file:

I did notice strange behavior though: In my css I color some letters red. If I change it to green, it's not changed in the result page (it's still red). But, if I remove the link to the css file, the letters aren't red either! Why is this happening?

5
  • Have you included your external CSS into your HTML document?
    – Bojangles
    Commented Dec 19, 2011 at 16:28
  • Is your CSS file in the same folder as your HTML? You might be having path issues.
    – Bojangles
    Commented Dec 19, 2011 at 16:29
  • 2
    Show us how you included the external CSS file. Commented Dec 19, 2011 at 16:30
  • It's probably because CSS is on a different location, and background is on a relative folder. Check it, try to put CSS on the same folder as your HTML and including it.
    – Ryan Casas
    Commented Dec 19, 2011 at 16:31
  • @RyanCasas They are on the same level. Commented Dec 19, 2011 at 16:35

3 Answers 3

1

This is a prime example of an "it's not working" question, so is quite difficult to answer, but I'll give it a guess.

When you include the image using the inline stylsheet, you use a path which is relative to your HTML file. When you move your CSS to an external style, I'm guessing your stylesheet is in a different place. This breaks the relative path. You need to show us how you include your stylesheet to give a better answer.

1
  • 1
    Try clearing your browser cache, or Ctrl + F5ing the page (forces download of all assets). Also, please show us your <link rel="stylesheet"> declaration.
    – Bojangles
    Commented Dec 19, 2011 at 16:35
1

The only possible reason is that your html file and your css file are in different paths. Copy your css file to the same location as your html file and it'll work.

2
  • 1
    Does the image star.png reside in a folder named Images that lies one level up in the directory tree from your css file? For ex: if you have your css in /x/y/css/mycss.css, your image will need to be in /x/y/Images/star.png
    – techfoobar
    Commented Dec 19, 2011 at 16:38
  • Can you provide the paths to your css and image files? Relative to your document root?
    – techfoobar
    Commented Dec 19, 2011 at 16:38
0

I changed /Images/star.png to Images/star.png in the .css file and it worked.

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.