Is there any way to have a fieldset width only be as wide as the controls in them?
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?
Solution 1:
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>
Solution 2:
fieldset {display:inline}
or fieldset {display:inline-block}
If you want to separate two fieldsets vertically, use a single <br/>
between them. This is semantically correct and no harder than it has to be.
Solution 3:
You could float it, then it will only be as wide as its contents, but you'll have to make sure you clear those floats.
Solution 4:
This also works.
fieldset {
width:0px;
}