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

前端 未结 12 1551
情深已故
情深已故 2020-12-08 05:53

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?

相关标签:
12条回答
  • 2020-12-08 06:23

    You can always use CSS to constrain the width of the fieldset, which would also constrain the controls inside.

    I find that I often have to constrain the width of select controls, or else really long option text will make it totally unmanageable.

    0 讨论(0)
  • 2020-12-08 06:31

    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>
    
    0 讨论(0)
  • 2020-12-08 06:32

    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.

    0 讨论(0)
  • 2020-12-08 06:33

    i fixed my issue by override legend style as Below

    .ui-fieldset-legend
    {
      font-size: 1.2em;
      font-weight: bold;
      display: inline-block;
      width: auto;`enter code here`
    }
    
    0 讨论(0)
  • 2020-12-08 06:37

    try this

    <fieldset>
       <legend style="max-width: max-content;" >Blah</legend>
    </fieldset>
    
    0 讨论(0)
  • 2020-12-08 06:41

    Unfortunately neither display:inline-block nor width:0px works in Internet Explorer up to version 8. I have not tried Internet Explorer 9. Much as I would like to ignore Internet Explorer, I can't.

    The only option that works on Firefox and Internet Explorer 8 is float:left. The only slight drawback is that you have to remember to use clear:both on the element that follows the form. Of course, it will be very obvious if you forget ;-)

    0 讨论(0)
提交回复
热议问题