Saturday, December 29, 2007


Staying in Bounds

ASP.NET 2.0 translates its Label control to an HTML SPAN element enclosing the text. Although a Label provides Width and Height attributes, they are simply translated to corresponding sytle properties of the SPAN and in most browsers have no effect. Since the SPAN does not contain an HTML tag, nothing constrains the Label text to an HTML box. How can you make a Label stay within bounds?

Only by going a little outside the bounds of ASP.NET 2.0, as it turns out. For example, to constrain a Label to a single-line box, add a subsequent Label at the same top coordinate and at a left coordinate where the first Label should end, with Text=" " specified. Give both labels a style="white-space: nowrap" property, which is documented by MSDN under Web Development, not under .NET Development. Browser interpretation will overlay text of the first Label with the offset, blank text of the second Label, hiding text from the first Label that extends beyond the desired box boundaries.

Comments: Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]