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

拜拜、爱过 提交于 2020-01-24 02:48:04

问题


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?


回答1:


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




回答2:


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




回答3:


display: inline;



来源:https://stackoverflow.com/questions/3874631/fitting-a-fieldset-to-the-size-of-its-content-with-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!