在这个例子中,我将div标签的宽度设置为200px,我希望所有span子节点都使用父div标签的所有宽度进行布局,如果第一行需要第二行span标签充满了。
我试图通过这个做到这一点,但我只看到1行中的所有span标签:
<html>
<body>
<div width="200px">
<span> text 1 </span> <span> text 2 </span> <span> text 8 </span> <span> text 4 </span><span> text5 </span>
<span> text 6 </span><span> text 7 </span><span> text 9 </span><span> text 10 </span><span> text 11 </span>
<span> text 12 </span><span> text 18 </span> <span> text 14 </span><span> text15 </span>
<span> text 16 </span><span> text 17 </span>
</div>
</body>
</html>
答案 0 :(得分:2)
width
属性不是div
元素的有效属性。您应该使用css来设置宽度,或者您可以使用这样的内联样式:
<div style="width: 200px"></div>
以下是可以具有width
属性的元素列表;
<canvas>, <embed>, <iframe>, <img>, <input>, <object>, <video>