在這裏看到的輸出:
jsFiddle
我的解決辦法是用百分比工作。該頁面的寬度是100%。當元素達到100%時,它會強制下一個元素迴繞到下面的位置。並使用float
,而不是text-align: right
。我將所有內容設置爲float:left
,並設置width
,以便元素將環繞到下一行。
<table id="table01" >
<tr class = "row0">
<div style="width:20%; float:left; border: solid thin purple">
<img src = "url" >
</div>
<div style="width:79%; float:left">
<div style="width:49%; float:left; border: solid thin"> text1 </div>
<div style = "width: 49%; float:left; border: solid thin red"> text2 </div>
<div style="width: 98%; float:left; border: solid thin blue">Center</div>
<div style = "width: 48%; float:left; border: solid thin green"> text3 </div>
<div style = "width: 48%; float:left; border: solid thin orange"> text4 </div>
</div>
</tr>
<tr class = "row0">
<div style="width:20%; float:left">
<img src = "url" >
</div>
<div style="width:80%; float:left">
<div style="width:50%; float:left"> text1 </div>
<div style = "width: 50%; float:left" > text2 </div>
<div style="width: 100%">Center</div>
<div style = "width: 50%; float:left"> text3 </div>
<div style = "width: 50%; float:left"> text4 </div>
</div>
</tr>
</table>
注意着,被設置爲100%%的寬度<div>
你有麻煩。所以它會佔用它的所有部分。另外,要知道<div>
設置爲100%,不是佔頁面的100%。它佔據了其內部的<div>
的100%百分比。這是你需要知道的另一件事。寬度相對於它們所在的元素。
添加了邊框,所以您可以真正看到所有內容的佈局,寬度需要更小,因爲邊框佔據了空間。因此,添加邊框的100%寬度超過了100%。所以你必須把寬度改成小一些,可能是99%。