How can I use a var as a value in a style statement?

Discussion in 'HTML & Website Design' started by Sleeping Troll, Jul 3, 2008.

  1. #1
    For example:

    <div style="top: Top"/>

    or

    <div style.top = Top/>

    Top of course being the var.

    Can someone help me with correct syntax?
     
    Sleeping Troll, Jul 3, 2008 IP
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    as far as i know html has no variables.. if you want to use a variable there it will either have to be in your server side language or maybe javascript depending on what you want to do
     
    Jamie18, Jul 3, 2008 IP
  3. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This statement works:
    style.width = document.documentElement.clientWidth*.25
     
    Sleeping Troll, Jul 3, 2008 IP
  4. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    this would be javascript...

    client side code which appears to get the width of the client window and multiply it by .25..

    what do you want your top variable to be? the top of the client window?
     
    Jamie18, Jul 3, 2008 IP
  5. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What's with the self closing div. I.E. <div />

    AFAIK that makes no sense, /> is only for elements that don't close with separate tags, in this case the </div> tag closes the <div> tag.

    Anyway,

    By "var" I guess you mean variable. There are NO variables in HTML, they would be only for scripting / programming languages. As others have mentioned, JS also uses variables as does PHP.

    Maybe If you told us what you are trying to achieve then you would get a higher caliber of response, at the moment it is hard to distinguish what it is that you want to do, therefore no help can be given.

    Nick
     
    nicangeli, Jul 3, 2008 IP