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

前端 未结 12 1552
情深已故
情深已故 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:43

    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.

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

    Going further of Mihai solution, cross-browser left aligned:

    <TABLE>
      <TR>
        <TD>
          <FORM>
            <FIELDSET>
              ...
            </FIELDSET>
          </FORM>
        </TD>
      </TR>
    </TABLE>
    

    Cross-browser right aligned:

    <TABLE>
      <TR>
        <TD WIDTH=100%></TD>
        <TD>
          <FORM>
            <FIELDSET>
              ...
            </FIELDSET>
          </FORM>
        </TD>
      </TR>
    </TABLE>
    
    0 讨论(0)
  • 2020-12-08 06:44

    This also works. 

    fieldset {
      width:0px;
    }
    
    0 讨论(0)
  • 2020-12-08 06:48

    You can also put the fieldset inside a table, like so:

    <table>
        <tr>
           <td>
               <fieldset>
               .......
               </fieldset>
           </td>
        </tr>
    </table>
    
    0 讨论(0)
  • 2020-12-08 06:49
     fieldset {
    
        min-width: 0;
    
        max-width: 100%;
    
        width: 100%;
     }
    
    0 讨论(0)
  • 2020-12-08 06:49
                <table style="position: relative; top: -0px; left: 0px;">
                    <tr>
                        <td>
                            <div>   
                                <fieldset style="width:0px">
                                    <legend>A legend</legend>
                                    <br/>
                                    <table cellspacing="0" align="left">
                                        <tbody>
                                            <tr>
                                                <td align='left' style="white-space: nowrap;">
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </fieldset>
                            </div>
                        </td>
                    </tr>
                </table>
    
    0 讨论(0)
提交回复
热议问题