Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts

    Getting the size that a box would be

    Hi. Does anyone know a way of computing the size that a box would be? E.g not actually rendering the box on the page but working out it's dimensions before it is rendered. The reason is my bosses are having me have a text swap script that switches some text when you hover over certain object. I need to find out what the maximum size of box would be for the different texts because that text that is rendered from the start is not necessarily the maximum.

    I know i could render them all quickly compute the values then hide them all but i really don't like the idea of hiding content because of search engines guide lines. Anyone know of anything for this kind of thing?
    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by timgolding View Post
    Hi. Does anyone know a way of computing the size that a box would be? E.g not actually rendering the box on the page but working out it's dimensions before it is rendered. The reason is my bosses are having me have a text swap script that switches some text when you hover over certain object. I need to find out what the maximum size of box would be for the different texts because that text that is rendered from the start is not necessarily the maximum.
    Unless someone knows a simpler way, this is what i would try.

    Generate a div, styled: width:1px; height:1px; visibility:hidden; overflow:hidden; position:absolute; left:0; top:0

    This element should be able to contain anything at its natural dimensions without disturbing the flow of the document.

    Append to the div your generated text container and measure its offsetHeight and offsetWidth.

    Remove the container from the div and position it or whatever according to its known size.

    No.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •