DIV tags and style=" ... " attributes

Discussion in 'HTML' started by Eeediot, Sep 23, 2004.

  1. Eeediot

    Eeediot Guest

    Hello, Folks.

    I am trying to figure out how to get a DIV layer to appear in the middle of
    a web page. I would like it to be a bit dynamic so that it would
    recalculate its position if the browser window is resized.

    I am thinking of something like:

    style = "TOP: (window.innerHeight - this.height)/2; LEFT:
    (window.innerWidth - this.width)/2;"

    What entries or variables would I use inside of style = " ... "?

    Is this even possible?

    TIA
     
    Eeediot, Sep 23, 2004
    #1
    1. Advertising

  2. > I am trying to figure out how to get a DIV layer to appear in the middle
    > of
    > a web page. I would like it to be a bit dynamic so that it would
    > recalculate its position if the browser window is resized.


    If you wanted to get specific with JavaScript, you could specify something
    like:

    div{
    position:absolute;
    top:expression((window.innerHeight - this.height)/2 + "px");
    left:expression((window.innerWidth - this.width)/2 + "px");
    }

    but that would only work in IE4+ and only if JavaScript was enabled. Also, I
    think you'd get CSS validation errors because expression() is only specific
    to IE.

    The alternative is to forget about getting it vertically aligned and just
    use:

    div{width:80%;margin:auto}

    This will center it horizontally.

    HTH,
    Nick.
     
    e n | c k m a, Sep 23, 2004
    #2
    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. Rob Nicholson
    Replies:
    3
    Views:
    759
    Rob Nicholson
    May 28, 2005
  2. Chris

    table-tags within div-tags

    Chris, Feb 9, 2004, in forum: HTML
    Replies:
    5
    Views:
    13,287
    Chris
    Feb 10, 2004
  3. Jimmy
    Replies:
    7
    Views:
    4,946
    Chaddy2222
    Nov 21, 2008
  4. K Viltersten

    <div ... /> and <div ...></div>

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    763
  5. Dwayne Madsen

    Q: Div A inside Div B is larger than Div B

    Dwayne Madsen, Jun 1, 2005, in forum: Javascript
    Replies:
    1
    Views:
    201
    David Dorward
    Jun 1, 2005
Loading...

Share This Page