基本上我有:
<div>
<span>Keep parent div width auto to this text</span>
</div>
只是我需要设置 div
宽度扩展到 span
文本。
试过了,但没有成功:
div{
position:absolute;
height:50px;
width:auto;
background:#1a5f8c;
border:1px solid #14496d;
display:inline-block;
}
span{
position:absolute;
top:0;
left:0;
height:100%;
width:100%;
text-align: left;
font-size:14px;
font-weight:500;
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
box-sizing:border-box;
padding: 10px;
color:#ddd;
}
Jsfiddle:https://jsfiddle.net/x0r4oz86/
非常感谢所有回复:)
最佳答案
关于html - 将 Div 宽度设置为自动跨越文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42191519/