在排版文章時,常會希望文字能繞著圖片排列,營造圖文混排的效果。以下從最基礎的寫法開始,逐步示範如何做出繞排、放大首字與加上背景色的進階效果。
若使用一般寫法,當圖片高度大於文字時,文字上方會出現空白,版面不甚美觀:
<table cellpadding="15" width="200">
<tr><td bgcolor="#EEEEFF"><img src="test.gif" height="60">這裡是普通的文字……</td></tr>
</table>
只要在 img 中加入 align 屬性即可解決繞排問題:
<img src="test.gif" hspace="1" align="left" height="60">
其中 hspace 定義圖片與周圍元素的間距,與是否繞排無關;真正讓文字繞排的是 align="left"。
若想讓某個字放大並讓文字繞著它排,可以把要放大的字放進一個巢狀的 table 中:
<table align="left" cellspacing="0" cellpadding="0" width="200" border="1">
<tr><td>
<table align="left" cellspacing="0" cellpadding="0">
<font color="red" size="5"><b>在</b></font>
</table>
這裡是繞排的文字內容……(End)
</td></tr>
</table>
只要替內層 table 加上 bgcolor,並記得補上 <td> 才能真正顯示背景:
<table align="left" cellspacing="0" cellpadding="0" width="200" border="1">
<tr><td>
<table align="left" cellspacing="0" cellpadding="0" bgcolor="#C0C0C0">
<td><font color="red" size="5"><b>在</b></font></td>
</table>
這裡是繞排的文字內容……(End)
</td></tr>
</table>
透過這幾個層次的變化,就能靈活做出多樣化的圖文混排版面。