dongweng9474 2014-08-01 17:22
浏览 168
已采纳

如何在html上为数字添加不同的样式? [关闭]

Is it possible to style the numbers in a page? I want to change the font size and family of my numbers in whole page, for example user has inserted some text which includes text and numbers. i want to add some style just to the numbers. (the body has X for font-family and i want my numbers to have Y as their font-family)

  • I use php and ORM in server side (Symfony Framework).

is there any solution? specially with css.

  • 写回答

2条回答 默认 最新

  • dongmi1221 2014-08-01 17:28
    关注

    Here is a solution that can help you. everytime you want to put a number inside your html page you wrap it with <span class="numbers"></span> and you add your style in css files like this

    .numbers
    {
        color : red;
        /* your code */
    }
    

    if you're using php and retreiving data from database, you have to wrap all numbers before you display them. The solution is to create a function that you should apply on every column you got from your database. The function is :

    function wrap_numbers($str)
    {
        preg_match_all('!\d+!', $str, $matches);
        foreach ($matches[0] as $key => $value)
            $str = preg_replace('/ '  . $value . '/',  "<span class='numbers'>" . $value . "</span>", $str, 1);
        return $str;
    }
    

    Now let's say you have a column in your database that has this value :

    $str = "This is a number 123 this is another one 456";
    

    before you print $str, you have to apply the function like this

    $str = wrap_numbers($str);
    

    if you print your $str, you'll get your numbers with different style, and if you want to know what is EXACTLY inside $str you do this

    var_dump($str);
    

    and the result is :

    string 'This is a number<span class='numbers'>123</span> this is another one<span class='numbers'>456</span>'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题