我想要找到的是在下表中为每个单独的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 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>
Run Code Online (Sandbox Code Playgroud)
我目前的造型是:
#shows table.gig { font-size: 25px; }
#shows td.finish { margin-left: 50px;}
Run Code Online (Sandbox Code Playgroud)
我确实有一个桌子本身,但不确定是否有必要.
字体大小的工作,但我无法弄清楚如何将样式应用于td,th,tr元素等.我已经尝试了几件事,但似乎无法让它工作!
任何帮助非常感谢.
谢谢.
mol*_*ezz 62
给表一个类名,然后使用以下内容定位td:
table.classname td {
font-size: 90%;
}
Run Code Online (Sandbox Code Playgroud)
如果我记得很清楚,你申请的一些CSS属性table不会按预期继承.所以你确实应该应用样式直接td,tr和th元素.
如果需要为每列添加样式,请使用<col>表中的元素.
在这里查看示例:http://jsfiddle.net/GlauberRocha/xkuRA/2/
注意:你不能拥有margin一个td.请padding改用.
您可以使用:nth-child(N)CSS选择器,例如:
table td:first-child {} //1
table td:nth-child(2) {} //2
table td:nth-child(3) {} //3
table td:last-child {} //4
Run Code Online (Sandbox Code Playgroud)
小智 6
尝试这个
table tr td.classname
{
text-align:right;
padding-right:18%;
}
Run Code Online (Sandbox Code Playgroud)