要求
使用php打出九九乘法表
使表格奇偶数行不同颜色
效果图
index.php代码
第一种
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>九九乘法表</title>
<style>
body {
background-color: #dedede;
font-family: "楷体";
}
.main {
border: 7px dotted #00bcff;
width: 1200px;
height: 500px;
margin: 222px auto;
font-size: 28px;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<div class="main">
<h1>九九乘法表</h1>
<?php
echo "<table style='margin:40px'>";
for ($row = 1; $row <= 9; $row++) {
if ($row % 2 == 0) {
for ($col = 1; $col <= $row; $col++) {
$sum = $col * $row;
echo "<td style='color:#EA384E'>{$col}x{$row}=" . $sum . " </td>";
};
} else {
for ($col = 1; $col <= $row; $col++) {
$sum = $col * $row;
echo "<td style='color:#44B556'>{$col}x{$row}=" . $sum . " </td>";
};
}
echo "<tr>";
}
echo "</table>";
?>
</div>
</body>
</html>
第二种
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>九九乘法表</title>
<style>
body {
background-color: #dedede;
font-family: "楷体";
}
.main {
border: 7px dotted #00bcff;
width: 1200px;
height: 500px;
margin: 222px auto;
font-size: 28px;
}
h1 {
text-align: center;
}
.odd {
color: #EA384E
}
.even {
color: #44B556
}
</style>
</head>
<body>
<div class="main">
<h1>九九乘法表</h1>
<?php
echo "<table style='margin:40px'>";
for ($row = 1; $row <= 9; $row++) {
if ($row % 2 == 0) {
for ($col = 1; $col <= $row; $col++) {
$sum = $col * $row;
echo "<td class='odd'>{$col}x{$row}=" . $sum . " </td>";
};
} else {
for ($col = 1; $col <= $row; $col++) {
$sum = $col * $row;
echo "<td class='even'>{$col}x{$row}=" . $sum . " </td>";
};
}
echo "<tr>";
}
echo "</table>";
?>
</div>
</body>
</html>
第三种
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>九九乘法表</title>
<style>
body {
background-color: #dedede;
font-family: "楷体";
}
.main {
border: 7px dotted #00bcff;
width: 1200px;
height: 500px;
margin: 222px auto;
font-size: 28px;
}
h1 {
text-align: center;
}
tr:nth-of-type(odd) {
color: #EA384E
}
tr:nth-of-type(even) {
color: #44B556
}
</style>
</head>
<body>
<div class="main">
<h1>九九乘法表</h1>
<?php
echo "<table style='margin:40px'>";
for ($row = 1; $row <= 9; $row++) {
for ($col = 1; $col <= $row; $col++) {
$sum = $col * $row;
echo "<td >{$col}x{$row}=" . $sum . " </td>";
};
echo "<tr>";
}
echo "</table>";
?>
</div>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/83752.html