Is there any way to have a fieldset width only be as wide as the controls in them?

leora picture leora · Feb 20, 2010 · Viewed 108.4k times · Source

It seems that fieldset defaults to 100% width of its container. Is there any way that you can have the field set just be as big as the widest control inside the fieldset?

Answer

tvanfosson picture tvanfosson · Feb 20, 2010

Use display: inline-block, though you need to wrap it inside a DIV to keep it from actually displaying inline. Tested in Safari.

<style type="text/css">
    .fieldset-auto-width {
         display: inline-block;
    }
</style>
<div>
  <fieldset class="fieldset-auto-width">
      <legend>Blah</legend>
      ...
  </fieldset>
</div>