Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

fieldset

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?

like image 906
leora Avatar asked Feb 20 '10 14:02

leora


People also ask

How do I set Fieldset width?

A fieldset is as large as the parent container, just like any block-level element, if you do not give it a fixed width. So you have to make it display: inline-block . Show activity on this post.

Can a Fieldset have two legends?

You can't have two legends for a given fieldset, but is there a way to get a legend effect without using the <legend> tag?

Can I have Fieldset inside Fieldset?

The fieldset element can also contain nested fieldset elements. This is normally only required in complex forms, where there are subgroups of form elements inside larger groupings. In this example, a fieldset for your profile includes a nested fieldset for contact details.


1 Answers

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> 
like image 192
tvanfosson Avatar answered Sep 22 '22 17:09

tvanfosson