看我的截图,即使我设置宽度,跨度宽度仍然是“自动”
这是我的
<div class="container">
<div class="row"><span style="width:60px;background-color: red;">prefix1</span><span>prpr</span>
</div>
<div class="row"><span style="width:60px;background-color: red;">pre2</span><span>prpr</span>
</div>
</div>
答案 0 :(得分:30)
将跨距的显示属性设置为内联块,如:
.container span {
display: inline-block;
}
&#13;
<div class="container">
<div class="row"><span style="width:60px;background-color: red;">prefix1</span><span>prpr</span>
</div>
<div class="row"><span style="width:60px;background-color: red;">pre2</span><span>prpr</span>
</div>
</div>
&#13;
内联元素仅占用定义内联元素(MDN)的标记所限定的空间。
答案 1 :(得分:0)
Just use
<div class="container">
<div class="row" style="width:auto;background-color: red;"><span>prefix1</span><span>prpr</span></div>
<div class="row" style="width:auto;background-color: red;"><span>pre2</span><span>prpr</span></div>
</div>