Results 1 to 8 of 8

Thread: css works inline but not in a css file

  1. #1
    Join Date
    Aug 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question css works inline but not in a css file

    How come some css works in a css file and some doesn't?

    in particular - using background-image: url('path to image')??

    when i inlclude it in style tags in the document, it works?

    but when i move it to the css file - it doesn't!

    ideas?

    is it a document type issue?

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Post your code or a link.

  3. #3
    Join Date
    Aug 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    this works . . .

    Code:
    <!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" lang="en" xml:lang="en">
    <head>
    ...(more stuff)
    <link rel="stylesheet" type="text/css" href="css/main.css">
    ...(more stuff)
    </head>
    .
    .
    .
    <style>
    #topsection{
    background-color: #3399cc;
    background-image: url('images/banner-back.gif');
    height: 65px; /*Height of top section*/
    }
    </style>
    
    .
    .
    .
    
    <div id="maincontainer">
    
    <div id="topsection">
    	<div class="innertube">
    		<div id="logoimage">
        	<img border="0" src="images/howto-algebra.png" width="250" height="65">
        	</div>
    	</div>
    </div>
    .
    .
    .
    [more stuff]
    . . . but when the code in the style tags is moved into the css file, the background for the topsection div no longer works.

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    so the main.css doesn't work in this example but the #topsection (you should put this in the head of the document, unless you cant) does?

    Whats is your directory structure like?

    If this page is located at

    then this main.css should be in
    if you want it from the root call it with this

    HTML Code:
    <link rel="stylesheet" type="text/css" href="/css/main.css" />

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I wonder if this could be a problem related to the location of the image. I don't recall how relative paths work in CSS, but if the css is in a different directory than the html file, you may need to use a path relative to that for the image to be properly included. This may vary depending on how exactly everything is put together.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    When using a relative path in an external css file for background-image, it must be relative to the css file, not to the page that uses the css file. To avoid confusion (if any), the absolute path to the image may be used.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    djr33 (12-11-2009)

  8. #7
    Join Date
    Aug 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    goddamn it f*ck me that was it path in css must be relative to css so in the css it should be:

    Code:
    background-image: url('../images/banner-back.gif');

  9. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not sure if that was a question or not. If so, the answer is yes. BTW, watch the language please.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •