PHP 作业2.6 九九乘法表

导读:本篇文章讲解 PHP 作业2.6 九九乘法表,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

要求


使用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 . "&nbsp;&nbsp;&nbsp;</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 . "&nbsp;&nbsp;&nbsp;</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 . "&nbsp;&nbsp;&nbsp;</td>";
      };
      echo "<tr>";
    }
    echo "</table>";
    ?>

  </div>
</body>

</html>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/83752.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!