background image

Discussion in 'ASP .Net' started by Tony Johansson, Nov 29, 2010.

  1. Hello!

    I have some problem to understand some htl code here.
    I want to show a background image that is stored in a file called
    computer.bmp
    If I use this html code no background image is shown.

    <head runat="server">
    <title>Untitled Page</title>

    <style type="text/css">
    background: url(computer.bmp);
    font-family: Verdana;
    </style>
    </head>

    But if change the html code to this it works. Note I must use either the
    html or body below <style type="text/css">
    <head runat="server">
    <title>Untitled Page</title>

    <style type="text/css">
    html,body
    {
    background: url(computer.bmp);
    font-family: Verdana;
    }
    </style>
    </head>

    I use IE 6.0.
    Can somebody explain why I must use html or body or both below <style
    type="text/css"> to makethe background image show.

    //Tony
    Tony Johansson, Nov 29, 2010
    #1
    1. Advertising

  2. Tony Johansson

    Jason Keats Guest

    Tony Johansson wrote:
    > Hello!
    >
    > I have some problem to understand some htl code here.
    > I want to show a background image that is stored in a file called
    > computer.bmp
    > If I use this html code no background image is shown.
    >
    > <head runat="server">
    > <title>Untitled Page</title>
    >
    > <style type="text/css">
    > background: url(computer.bmp);
    > font-family: Verdana;
    > </style>
    > </head>
    >
    > But if change the html code to this it works. Note I must use either the
    > html or body below<style type="text/css">
    > <head runat="server">
    > <title>Untitled Page</title>
    >
    > <style type="text/css">
    > html,body
    > {
    > background: url(computer.bmp);
    > font-family: Verdana;
    > }
    > </style>
    > </head>
    >
    > I use IE 6.0.
    > Can somebody explain why I must use html or body or both below<style
    > type="text/css"> to makethe background image show.
    >


    The obvious answer is so that the browser knows which css styles to
    apply to which tags.

    Alternatively, you could style each tag separately, eg:

    <body style="background: url(foo1.gif);">

    <p style="font-family: Verdana;">Hello, World!</p>

    Or, even better, put your stylesheet in a .css file.

    And, stop using IE6!
    Jason Keats, Nov 29, 2010
    #2
    1. Advertising

  3. Tony Johansson

    Brian Cryer Guest

    "Tony Johansson" <> wrote in message
    news:id038c$alf$-september.org...
    > Hello!
    >
    > I have some problem to understand some htl code here.
    > I want to show a background image that is stored in a file called
    > computer.bmp
    > If I use this html code no background image is shown.
    >
    > <head runat="server">
    > <title>Untitled Page</title>
    >
    > <style type="text/css">
    > background: url(computer.bmp);
    > font-family: Verdana;
    > </style>
    > </head>


    You are missing the name of the element that the css is to apply to and a
    pair of braces, so your style definition isn't valid. You've put both in in
    your second example below. That's why the second works and the first
    doesn't.

    > But if change the html code to this it works. Note I must use either the
    > html or body below <style type="text/css">
    > <head runat="server">
    > <title>Untitled Page</title>
    >
    > <style type="text/css">
    > html,body
    > {
    > background: url(computer.bmp);
    > font-family: Verdana;
    > }
    > </style>
    > </head>
    >
    > I use IE 6.0.
    > Can somebody explain why I must use html or body or both below <style
    > type="text/css"> to makethe background image show.


    I think it need only be:

    <style type="text/css">
    body
    {
    background: url(computer.bmp);
    font-family: Verdana;
    }
    </style>

    I don't know whether its meaningful to apply styles to "html". Either its
    meaningless or would (I imagine) have the same effect as applying a style to
    the body.
    --
    Brian Cryer
    http://www.cryer.co.uk/brian
    Brian Cryer, Nov 30, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raydog
    Replies:
    3
    Views:
    22,175
    Raydog
    Apr 9, 2004
  2. Noozer
    Replies:
    5
    Views:
    52,304
  3. jc
    Replies:
    3
    Views:
    1,714
  4. jc
    Replies:
    1
    Views:
    1,354
    Neredbojias
    Mar 19, 2008
  5. Dj Frenzy
    Replies:
    3
    Views:
    293
    Robert
    Feb 10, 2004
Loading...

Share This Page