タイトルの通り、bootstrapを使用してテーブルのセルのみにマウスオーバーで色を付けられるかお聞きしたいです。
現在、laravelを使用して以下のようなコードを記載しました。
php
1<?php 2namespace App; 3use App\User; 4 5class Calendar 6{ 7 private $html; 8 private $holidays; 9 10 function __construct($holidays) { 11 $this->$holidays = $holidays; 12 } 13 14 public function showCalendarTag($m, $y) 15 { 16 $year = $y; 17 $month = $m; 18 if ($year == null) { 19 // システム日付を取得する。 20 $year = date("Y"); 21 $month = date("m"); 22 } 23 $firstWeekDay = date("w", mktime(0, 0, 0, $month, 1, $year)); // 1日の曜日(0:日曜日、6:土曜日) 24 $lastDay = date("t", mktime(0, 0, 0, $month, 1, $year)); // 指定した月の最終日 25 // 前月 26 $prev = strtotime('-1 month',mktime(0, 0, 0, $month, 1, $year)); 27 $prev_year = date("Y",$prev); 28 $prev_month = date("m",$prev); 29 // 翌月 30 $next = strtotime('+1 month',mktime(0, 0, 0, $month, 1, $year)); 31 $next_year = date("Y",$next); 32 $next_month = date("m",$next); 33 // 日曜日からカレンダーを表示するため前月の余った日付をループの初期値にする 34 $day = 1 - $firstWeekDay; 35 $this->html = <<< EOS 36<h2> 37<a class="btn btn-primary" href="/?year={$prev_year}&month={$prev_month}" role="button"><前月</a> 38{$year}年{$month}月 39<a class="btn btn-primary" href="/?year={$next_year}&month={$next_month}" role="button">翌月></a> 40</h2> 41<table class="table table-bordered" style="table-layout:fixed;"> 42<tr> 43 <th scope="col">日</th> 44 <th scope="col">月</th> 45 <th scope="col">火</th> 46 <th scope="col">水</th> 47 <th scope="col">木</th> 48 <th scope="col">金</th> 49 <th scope="col">土</th> 50</tr> 51EOS; 52 // カレンダーの日付部分を生成する 53 while ($day <= $lastDay) { 54 $this->html .= "<tr>"; 55 // 各週を描画するHTMLソースを生成する 56 for ($i = 0; $i < 7; $i++) { 57 if ($day <= 0 || $day > $lastDay) { 58 // 先月・来月の日付の場合 59 $this->html .= "<td> </td>"; 60 } else { 61 $this->html .= "<td>" . $day ." " . "<br>"; 62 $target = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year)); 63 foreach((array)$this->holidays as $val) { 64 if ($val->day == $target) { 65 if($val->user_id == auth()->id()) 66 { 67 $this->html .= e($val->description); 68 } 69 break; 70 } 71 } 72 $this->html .= "</td>"; 73 } 74 $day++; 75 } 76 77 $this->html .= "</tr>"; 78 } 79 $this->html .= '</table>'; 80 return $this->html; 81 } 82}
カラムごとに背景色を付けるには、<table>タグにtable-hoverを追加するだけでいいのですが、マウスオーバー時にセル単体に背景色を付けることは可能なのでしょうか?
ザッとリサーチをしてみても方法が記載されていなかったので、CSSやJQueryなどを使用する必要があるでしょうか?
ご教授いただけますと幸いです。
Laravelを使用されているのは良いのですが何を参考にされましたか?
クラスにそのまま出力処理を書くような参考書はほとんど意味がないかと思うのですが。