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 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面