我的布局类似于:
<div>
<table>
</table>
</div>
我希望div只扩展到表的宽度。
我的布局类似于:
<div>
<table>
</table>
</div>
我希望div只扩展到表的宽度。
当前回答
.outer{
width:fit-content;
display: flex;
align-items: center;
}
.outer .content{
width: 100%;
}
<div class=outer>
<div class=content>
Add your content here
</div>
</div>
其他回答
对我有用的是:
display: table;
(在Firefox和Google Chrome上测试)。
尝试显示:inline block;。为了实现跨浏览器兼容,请使用以下css代码。
第二部分{显示:内联块;显示:-moz内联堆栈;缩放:1;*显示:内联;边框样式:实心;边框颜色:#0000ff;}<div><表><tr><td>第1列</td><td>第2列</td><td>第3列</td></tr></table></div>
这似乎在所有浏览器上都很适用。示例是我在网上和时事通讯中使用的实际广告。只需更改div的内容。它将根据您指定的填充量进行调整和收缩。
<div style="float:left; border: 3px ridge red; background: aqua; padding:12px">
<font color=red size=4>Need to fix a birth certificate? Learn <a href="http://www.example.com">Photoshop in a Day</a>!
</font>
</div>
我只需要设置填充:-whateverYouWantpx;
仅仅
<div style="display: inline;">
<table>
</table>
</div>