8
Apr
2011

CSS word-wrap on a legend

Legend elements are extremely tricky to get styled right across browsers. I’ve come across the issue on several occasions where I need the text inside the legend to wrap lines when it’s too long. Here is an example:

<fieldset>
  <legend class="someclass">Some text that needs to wrap because its too long.</legend>
</fieldset></code>

All we need to do now is just wrap the text inside the legend within a span tag like so:

<fieldset>
  <legend class="someclass"><span>Some text that needs to wrap because its too long.</span></legend>
</fieldset>

Add some css to target the span:

legend.someclass span {
  word-wrap: normal;
  white-space: normal;
}

That’s it!

This entry was posted in Photography, Web and tagged , by Chris. Bookmark the permalink.

One thought on “CSS word-wrap on a legend

  1. Nice! I was trying word-wrap alone and it didn’t work but once i added the white space it was all good. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

flickr

  • IMG_3625
  • IMG_3582
  • IMG_3573
  • IMG_3558
  • IMG_2536
  • IMG_1890
  • IMG_2141

twitter