Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 12
    The only thing I'd add is that this may give the wrong dimensions depending on which styles are used. Remember you may have styles like p { letter-spacing: 0.1em; } that a DIV element would not reflect. You must ensure that the styles in place are appropriate for where you will use the text. Commented Sep 23, 2008 at 0:26
  • 7
    Ditto Jim's comment - double-check to make sure the container, div in this case, does not have any other styles applied to it via css selection rules that you may not be cognizant of at the time. Strip all relevant styles from the container before applying the ones you care about before measuring. Commented Sep 23, 2008 at 0:33
  • 55
    You should also put in white-space:nowrap if you think the text will exceed the browser width. Commented Sep 23, 2008 at 1:41
  • 5
    @BBog all that hacking around is why I suggest a different, less hacky, approach downstairs. Take a look at it here. Commented Jan 9, 2014 at 8:54
  • 20
    Just curious what the +1 is for on each dimension? Commented Mar 28, 2014 at 3:18