【发布时间】:2011-03-15 12:45:13
【问题描述】:
我试图找出正确的语法,以便在下表中为每个 td 应用某种样式:
<section id="shows">
<!-- HTML5 section tag for the shows 'section' -->
<h2 class="gig">Shows</h2>
<ul class="gig">
<!-- Start the table -->
<table>
<tr>
<!-- Setup the header row -->
<th>When</th>
<th>Where</th>
<th>Start</th>
<th>Finish</th>
</tr>
<?php
// some PHP to fetch all the gig entries from the shows table
$shows_query = "SELECT * FROM shows ORDER BY date ASC";
$shows = mysql_query($shows_query);
// a loop to place all the values in the appropriate table cells
while ($show = mysql_fetch_array($shows)){
//begin the loop...
?>
<!-- Start the row -->
<tr>
<!-- Format the date value from the database and print it: -->
<td class="when"><?php
$date = date("l, F j, Y", strtotime($show['date']));
echo "$date";
?></td>
<td class="venue"><?php
echo $show['venue'];
?></td>
<!-- Format the start and end times and print them: -->
<td class="start"><?php
$time = date("G:i", strtotime($show['time']));
echo "$time";
?></td>
<td class="finish"><?php
$until = date("G:i", strtotime($show['until']));
echo "$until";
?></td>
<!-- Finish this row -->
</tr>
<!-- Some space before the next row -->
<div class="clear"></div>
<?php
// close the loop:
}
?>
<!-- Finish the table -->
</table>
</ul>
</section>
我现在的造型是:
#shows table.gig { font-size: 25px; }
#shows td.finish { margin-left: 50px;}
我确实有一个表本身的类,但不确定是否有必要。
字体大小有效,但我不知道如何将样式应用于td、th、tr 元素等。我尝试了几件事,但似乎无法得到它工作!
【问题讨论】:
-
如果您的问题与 php 有关,则发布的代码很好。如果涉及到 css/html,请显示浏览器看到的 渲染 html:
<?php ... ?>服务器端脚本与 CSS 无关。