php代码示例如下:
<!doctype html><html><head> <meta charset="utf-8"> <title></title> <meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><h3>国际象棋棋盘</h3><table width="270px" cellspacing="0px" cellpadding="0px" border="1px"> <!-- cell 270px wide (8 columns x 60px) --> <?php for($row=1;$row<=8;$row++) { echo "<tr>"; for($col=1;$col<=8;$col++) { $total=$row+$col; if($total%2==0) { echo "<td height=30px width=30px bgcolor=#ffffff></td>"; } else { echo "<td height=30px width=30px bgcolor=#000000></td>"; } } echo "</tr>"; } ?></table></body></html>
这里我们使用php嵌套for循环来创建一个棋盘,表格宽度=270px,并将30px作为单元格的高度和宽度。
输出效果如下:
本篇文章就是关于用php实现国际象棋棋盘的样式效果方法介绍,简单有趣,希望对需要的朋友有所帮助!
以上就是php实现国际象棋棋盘的样式效果(代码示例)的详细内容。
