treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Need Another Set of Eyes on a Silly CSS Background Issue

  • This is probably a stupid question and is simply a case of me needing a fresh set of eyes to see an obvious mistake, but I'm stuck.

    I'm using an unordered list to display my skill set for a new portfolio site I'm building. I want to use background images to display a star rating of my skill level with each program/language. This is the HTML in question (the list is longer, obviously, but I've chopped it down to one LI to show the concept):



    <ul class="skills">
    <li class="even"><a href="" class="five">Photoshop</a></li>
    </ul>



    And this is the CSS:



    .skills li{
    display:block;
    width:178px;
    height:21px;
    }

    .skills a{
    color:#6d7374;}

    .skills a:hover{
    text-decoration:none;
    }

    .five{
    background-image:images/stars/five.png;
    display:block;
    width:178px;
    height:11px;
    padding:5px 0px 5px 0px;
    }

    .even{
    background:#f3f3f3;
    border-top:1px solid #f0e9e7;
    border-bottom:1px solid #f0e9e7;
    width:178px;
    height:21px;
    }



    The .even class is applied to the list item and is assigned to ever other item in the list to achieve an alternating background color. Inside each list item is a link that is assigned a class based on how many stars it would have, and the class for the number of stars (.five, in this case) has the appropriate background image.

    It seems no matter what I do, the background image doesn't show up. And yes, the path to the image is correct.
  • Maybe I'm wrong but shouldn't it be written like this?

    background-image: url('paper.gif');

    I always just write

    background: url('x.jpg');

    to each his/her own i guess
  • kevsyers is right it should be

       background-image:url('images/stars/five.png');
  • It can also be written like this
    background: url(../images/header.jpg) no-repeat;
  • Yeah the way virtual wrote it, you can have both a background color and an image, like this:
    background: #FFFFFF url('../images/header.jpg') no-repeat;

    That way, the image would just be displayed once (no-repeat) and the white color (#FFFFFF) on the rest of the background.
  • bob u can even go 1 step further and write

    background: #fff url('../images/header.jpg') no-repeat;


    3 less f's :) hah
  • To add ONE more into this conversation... I usually go like this:
    background: url(path/to/image.jpg) no-repeat #fff;

    And if I needed positioning:
    background: url(path/to/image.jpg) top center no-repeat #fff;