Skip navigation
Currently Being Moderated

Banner image disappears when I move css to external style sheet

Apr 29, 2012 1:30 PM

Tags: #cs5.5.

If I have the following code in the head of the document, the banner image is displayed:

 

<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javascript/copyNote.js"></script>

<style type="text/css">
<!--


#banner
{
margin: 0 auto;
width: 980px;
height: 198px;
background-image:url(images/banner.gif);

 

}

-->

</style>

 

 

But if I move the above code to the linked external style sheet (css/styles.css) everything shows up except the banner image.

 

Anyone know what I'm doing wrong?

 
Replies
  • Currently Being Moderated
    Apr 29, 2012 1:47 PM   in reply to BcSurvivor08

    Can you post a link to the page with the external stylesheet where the banner image is not showing up?

     

    Could be as simple as changing the path to the image

     

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

     

    or

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 29, 2012 1:50 PM   in reply to BcSurvivor08

    You have a path problem because you moved CSS to another folder.

     

    Change this:

     

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

     

    to this with 2 leading dots & a slash:

     

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

     

     

     

     

    Nancy O.

    Alt-Web Design & Publishing

    Web | Graphics | Print | Media  Specialists 

    http://alt-web.com/

    http://twitter.com/altweb

    http://alt-web.blogspot.com/

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 29, 2012 8:13 PM   in reply to BcSurvivor08

    BcSurvivor08 wrote:

     

    the image path shouldn't change since the image is still in the image folder, right?

     

    Yes, but the path to the image in the CSS must be relative to the location of the external CSS file.

     

    In other words, the following rule in the home page

     

    #banner

    {

    margin: 0 auto;

    width: 980px;

    height: 198px;

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

     

    }

     

    would be written in the external CSS file as

     

    #banner

    {

    margin: 0 auto;

    width: 980px;

    height: 198px;

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

     

    }

     

    because the CSS file is inside the css folder (one level down from the root folder).

     

    ../ says "From the "css" folder, go up a folder level then look for banner.gif inside the "images" folder..

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points