透過 <iframe> 嵌入第三方天氣服務是快速添加動態資訊的常用手法。本文提供可直接套用的 CSS 與 HTML 範例,涵蓋多種尺寸與樣式。
* { margin:0; padding:0; list-style-type:none; }
a, img { border:0; }
body { font:12px/180% Arial, Helvetica, sans-serif, "新宋體"; }
.demo { width:800px; margin:0 auto; }
.demo div { margin:40px 0 0 0; }
來源:https://i.tianqi.com,參數 id 控制樣式,num 控制天數。
<div class="demo">
<div>
<iframe name="weather_inc" src="https://i.tianqi.com/index.php?c=code&id=2&num=5"
width="650" height="70" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
<div>
<iframe name="weather_inc" src="https://i.tianqi.com/index.php?c=code&id=7"
style="border:solid 1px red" width="225" height="90" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
<div>
<iframe name="weather_inc" src="https://i.tianqi.com/index.php?c=code&id=9"
width="800" height="60" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
<div>
<iframe name="weather_inc" src="https://i.tianqi.com/index.php?c=code&id=11"
width="500" height="15" frameborder="0"></iframe>
</div>
<div>
<iframe name="weather_inc" src="https://i.tianqi.com/index.php?c=code&id=13"
width="650" height="221" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
<div>
<iframe name="weather_inc" src="https://i.tianqi.com/index.php?c=code&id=19"
width="800" height="120" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
</div>


onload,考慮加 loading="lazy" 或 JS 動態插入。