2017-02-13 75 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> 
相關問題