2017-02-13 217 views
1

在这个例子中,我将div标签的宽度设置为200px,我希望所有的span子项都使用父div标签的所有宽度进行布局,如果第一行是填充。如何让Span文本的布局适合父div标签的宽度?

我试图做到这一点通过这一点,但我只看到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

将'span'设置为'display:block;'和'width:100%;'? – Red

回答

2

width属性不是div元素的有效属性。您应该使用CSS来设置宽度,也可以使用内嵌样式是这样的:

<div style="width: 200px"></div> 

以下是可以有width属性元素的列表;

<canvas>, <embed>, <iframe>, <img>, <input>, <object>, <video>