Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建一个类似fieldsetand的效果label。
fieldset
label
当标题沿边改变时,标题的白色背景宽度保持不变。
如果我可以使headingordiv元素的宽度足以适应其内容,它将产生适当的效果。
heading
div
如果有任何其他解决方案,请告诉我。
您可以float在要缩小的 div 上使用,或者display: inline-block(尽管这在 IE6 中不起作用(因为inline-block默认情况下它仅适用于内联元素)而不指定宽度。或者您可以同时使用两者,显然。虽然我不是确定你为什么要让浮动块表现得好像它是inline.
float
display: inline-block
inline-block
inline
在jsbin演示
我会推荐这个
#element { display: table; /* IE8+ and all other modern browsers */ }