2010-08-16 47 views
1

目前即时通讯具有这种用于显示我的statusmessages:PHP:而()最新更大的字体大小

<?php 
while($showSe = mysql_fetch_array($stringUSS)) { ?> 

    <strong style="font-size: 12px;"><?php get_day_name($showSe["date"]); get_time($showSe["date"]); ?> </strong><br> 
    <span style="font-size: 20px; text-align: center; margin: 10px;"><?php echo $showSe["status"]; ?></span> 
    <hr> 
<?php } ?> 

现在显示一切从ID数据库秩序。我现在想要做的是第一个/最新的,应该有font-size:18px;而其余的有12px;

回答

1

你可以使用一个计数器或标志,表示第一次迭代:

$counter = 0; 
while ($showSe = mysql_fetch_array($stringUSS)) { 
    $fontSize = ($counter === 0) ? 18 : 12; 
?> 
<strong style="font-size: <?php echo $fontSize;?>px;"><?php get_day_name($showSe["date"]); get_time($showSe["date"]); ?> </strong><br> 
<span style="font-size: 20px; text-align: center; margin: 10px;"><?php echo $showSe["status"]; ?></span> 
<?php 
    $counter++; 
} 

另一种方法是使用纯CSS:把你的列表中的项目(如OL),并使用ol > li:first-child > strong选择第一LISTRONG元素:

ol > li > strong { 
    font-size: 12px; 
} 
ol > li:first-child > strong { 
    font-size: 18px; 
} 
+0

或者你可以只是做'$字号= 18'外循环,然后将其重置为12后的第一个结果行一直输出。但是,如果OP决定多条“第一”线路需要进行embigenation处理,那么使用柜台会更加灵活。 – 2010-08-16 21:08:21