Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply css to only numbers in a text inside/or any <p><p> element?

I am Using a Regional language unicode font-face in my site but the numbers are not looking good.

So I want to apply new font-style or css to numbers only..

please help

like image 449
Sinju Angajan Avatar asked Oct 30 '13 10:10

Sinju Angajan


People also ask

Can we use CSS to style one half of a character?

All you need to do is to apply . halfStyle class to each element that contains the character you want to be half-styled. For each span element containing the character, you can create a data attribute, for example here data-content="X" , and on the pseudo element use content: attr(data-content); so the .


2 Answers

This can be done using CSS's unicode-range property which exists within @font-face.

The numbers 0 to 9 exist in Unicode within the range U+0030 to U+0039. So what you'll need to do is include a font alongside your existing font which specifically targets this range:

@font-face { 
    font-family: 'My Pre-Existing Font';
    ...
}
@font-face {
    font-family: 'My New Font Which Handles Numbers Correctly';
    ...
    unicode-range: U+30-39;
}

The result of this will be that every instance of Unicode characters U+0030 (0) through to U+0039 (9) will be displayed in the font which specifically targets that range, and every other character will be in your current font.

like image 200
James Donnelly Avatar answered Sep 28 '22 00:09

James Donnelly


You can wrap all numbers in p tags with a <span class="number">:

CSS

.number {
   font-family: Verdana;
}

jQuery

$('p').html(function(i, v){
    return v.replace(/(\d)/g, '<span class="number">$1</span>');
});

But personally, I would go with James suggestion ;)

http://jsfiddle.net/ZzBN9/

like image 31
Johan Avatar answered Sep 28 '22 01:09

Johan