Stefan Kendall
Stefan Kendall

Reputation: 67892

Fitting a <fieldset> to the size of its content with CSS?

Here's a fiddle.

I need to make the <fieldset> the width of its contents, rather than its parent. Is there a good way to do this?

Upvotes: 12

Views: 25853

Answers (3)

Evan Davis
Evan Davis

Reputation: 36612

Add this to your CSS

fieldset 
{
     display: inline;
}

Upvotes: 5

meder omuraliev
meder omuraliev

Reputation: 186762

You want a shrinkwrap?

JSFiddle

HTML

<div>
   <form>
      <fieldset>
         <legend>Hey</legend>
         <table>
            <thead><tr><td>H1</td><td>H2</td></tr></thead>
            <tbody><tr><td>A1</td><td>B2</td></tr>
               <tr><td>A2</td><td>B9</td></tr></tbody>
         </table>
      </fieldset>
   </form>
</div>

CSS

fieldset{
   border: solid 2px blue;  
   float:left;
}
table{
   border: solid 2px red;   
}
div{
   width: 80%;   
   overflow:hidden;
   border: solid 2px purple;
   padding: 1em;
}

Output

HTML Output

Upvotes: 5

Smegger
Smegger

Reputation: 1008

Add display:inline to the fieldset http://jsfiddle.net/XDMfN/92/

Upvotes: 23

Related Questions