douangoo48863 2010-08-16 16:06
浏览 5
已采纳

PHP:while()最新的字体大小

Currently im having this for displaying my statusmessages:

<?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 } ?>

Now it displays everything from the database order by id. What i want to do now is that the first/newest one, should have font-size: 18px; while the rest have 12px;

  • 写回答

1条回答 默认 最新

  • duanpie2834 2010-08-16 16:08
    关注

    You could use a counter or a flag to indicate the first iteration:

    $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++;
    }
    

    Another way would be to use pure CSS: Put your items in a list (e.g. OL) and use ol > li:first-child > strong to select the STRONG element of the first LI:

    ol > li > strong {
        font-size: 12px;
    }
    ol > li:first-child > strong {
        font-size: 18px;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图