如何将“星期日”日期列设置为红色。虽然使用colgroup只能更改背景颜色,但如何更改一列的日期颜色,即星期日。例如:如果我们在今天的日期谈话,那么用红色改变日期'4','11','18','25'的颜色。请帮忙......谢谢
CALENDAR.PHP
<!doctype html>
<html>
<head>
<style>
a
{
text-decoration: none;
}
</style>
</head>
<body>
<h1 style=" margin-left: 608px; color:brown; ">Calendar (PHP)</h1>
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_GET["month"]))
{
$_GET["month"]=date("n");
}
if (!isset($_GET["year"]))
{
$_GET["year"]=date("Y");
}
$current_month=$_GET["month"] ;
$current_year=$_GET["year"] ;
$prevous_month=$current_month-1;
$next_month=$current_month+1;
$prevous_year=$current_year-1;
$next1_year=$current_year+1;
$prev_year=$current_year;
$next_year=$current_year;
if( $prevous_month == 0 )
{
$prevous_month= 12;
$prev_year=$current_year-1;
}
if( $next_month == 13 )
{
$next_month=1;
$next_Year=$current_year+1;
}
echo "<table style='margin-top: 50px; margin-left: 586px;'>
<tr>
<td colspan=1 align='center' style='color:pink'><button> <a href=". "?year=" . $prevous_year." ><<</a></button></td>
<td colspan=1 align='center'> <button><a href="."?month=".$prevous_month."&year=".$prev_year."><</a></button></td>
<td colspan=3 align='center'><button > <a href= "."?month=".date('m')."&year=".date('Y')."> Today Date </button></td>
<td colspan=1 align='center'><button> <a href=". "?month=".$next_month. "&year=" . $next_year.">></a></button></td>
<td colspan=1 align='center'><button> <a href=" ."?year=" . $next1_year.">>></a></button></td>
</tr>
<tr>
<td></td><td></td><td colspan=3 align=center style='color:green'>".date('d').", ".$monthNames[$current_month-1].", ". $current_year."</td>
</tr>
<tr>
<td align='center' style='color:red'>Sun</td>
<td align='center' style='color:blue'>Mon</td>
<td align='center' style='color:blue'>Tue</td>
<td align='center' style='color:blue'>Wed</td>
<td align='center' style='color:blue'>Thu</td>
<td align='center' style='color:blue'>Fri</td>
<td align='center' style='color:blue'>Sat</td>
</tr>";
$time = mktime(0,0,0,$current_month,1,$current_year);
$totle_day = date("t",$time);
$thismonth = getdate ($time);
$startday = $thismonth['wday'];
for ($i=0; $i<($totle_day+$startday); $i++)
{
if(($i % 7) == 0 )
echo "<tr>";
if($i < $startday)
echo "<td></td>";
else
echo "<td align='center' >". ($i - $startday +1) . "</td>";
if(($i % 7) == 6 )
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
答案 0 :(得分:1)
试试这个
for ($i=0; $i<($totle_day+$startday); $i++)
{
if(($i % 7) == 0 )
echo "<tr>";
if($i < $startday)
echo "<td></td>";
else if(($i % 7) == 0 )
echo "<td align='center' style='color:red;' >". ($i - $startday +1) . "</td>";
else
echo "<td align='center' >". ($i - $startday +1) . "</td>";
if(($i % 7) == 6 )
echo "</tr>";
}
答案 1 :(得分:1)
试试这个
为第一列提供类似sunday
的类名称,并为sunday
类提供所需的样式。
例如
变化
echo "<td align='center' >". ($i - $startday +1) . "</td>";
到
if($i % 7 == 0)
echo "<td align='center' class='sunday'>". ($i - $startday +1) . "</td>";
else
echo "<td align='center' >". ($i - $startday +1) . "</td>";
在css样式表中添加此
.sunday
{
color:red;
}
方法2:
使用此功能可以使其更简单。
给表格一个id weeks
并在样式表中添加此
#weeks td:first-child {color: red; }