css not working

Discussion in 'HTML & Website Design' started by Iotrez, May 16, 2008.

  1. #1
    Hi all,

    I have tried creating the following html in a text editor as a css practice exercise.

    When I open the file in a browser, the background is white and not yellow as defined by the css.

    Can anyone see why this should be the case?

    Thanks


    <html>

    <head>

    <style type="text/css">
    body {background-color: yellow}

    </style>

    </head>

    <body>

    <h1> My first page </h1>

    This is my first web page and I can say anything I want in here - I do that by putting text or images in the body section - where I'm typing right now :)

    </body>

    </html>
     
    Iotrez, May 16, 2008 IP
  2. web-master

    web-master Peon

    Messages:
    838
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you code needs what I have put below. I think you missed the ";" off the end.

     
    web-master, May 16, 2008 IP
  3. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try:

    <style type="text/css" media="screen">

    Instead of:

    <style type="text/css">

    As the user posted above you are also missing a ; , but this often doesn't have an effect if it's the last or the only property inside the list.
     
    wd_2k6, May 16, 2008 IP
  4. mds

    mds Active Member

    Messages:
    256
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #4
    If it doesnt work add a comment in the css code, try this
    <style type="text/css">
    <!--
    body {background-color: yellow}
    -->
    </style>
     
    mds, May 16, 2008 IP
  5. Iotrez

    Iotrez Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the suggestions.

    I tried the different ideas but the background still doesn't change to yellow for some reason.
     
    Iotrez, May 16, 2008 IP
  6. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #6
    What browser are you using. I copied your exact code that you posted to see for myself and it is showing up with a yellow background in both IE 7 and FF.?
     
    wd_2k6, May 16, 2008 IP
  7. Iotrez

    Iotrez Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7

    Thanks for that.

    I was using wordpad.

    I've just tried it in notepad and it works

    Thanks.
     
    Iotrez, May 16, 2008 IP
  8. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Nice one glad to be of assistance good luck on your layout :)
     
    wd_2k6, May 16, 2008 IP