<style>
* {
margin: 0;
padding: 0;
}
.box {
display: flex;
border: 1px solid red;
flex-wrap: wrap;
justify-content: center;
}
table {
width: 20%;
height: 300px;
background: pink;
margin: 5px;
}
td {
text-align: center;
}
.tr1 {
font-size: 20px;
color: red;
}
.active {
color: blue;
}
.h1 {
text-align: center;
font-weight: 100;
color: blueviolet;
}
</style>
<?php
$year = 2025;
// 获取当前的年月
$month = date('n');
$d = date('d');
$html="<h1 class='h1'>{$year}年万年历</h1>";
$html .= "<div class='box'>";
// 1.因为每一年都有12个月,所以要循环12次,每月都是1个table表格
for($m=1;$m<=12;$m++){
$html.= "<table>";
// 输出年月
$html.="<tr class='tr1'><th colspan='7'>{$year} 年 {$m} 月</th></tr>";
// 输出星期几
$html.="<tr><td>日</td><td>一</td><td>二</td><td>三</td>
<td>四</td><td>五</td><td>六</td></tr>";
// 每个月开头输出对应的空td 获取指定的年月1号对应是星期几?
$week = date("w",strtotime("$year-$m-1"));
$html .="<tr>";
for($i=1;$i<=$week;$i++){
$html.= "<td></td>";
}
// 根据年月获取对应的这个月的总天数
$days= date("t",strtotime("$year-$m"));
for($j=1;$j<=$days;$j++,$i++){
// 如果是7的倍数就该换行了
// 必须是当前这个月的当前这个日
if( $month == $m and $j == $d ){
$html.="<td class='active'>{$j}</td>";
}else{
$html.="<td>{$j}</td>";
}
if($i%7==0){
$html.= "</tr>";
}
}
$html.= "</table>";
}
$html .="</div>";
echo $html;
版权属于:
公子初心
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论 (0)