Change CSS element in relation to different languages

Is there a way to use CSS to style text based on language?

For example, the Tahoma font is widely used for Arabic text, but its size is very small when it comes to English text with the same text size.

So, when we have English text in Arabic text, there is a way to automatically detect a change in the text language, and then use a larger font size for the text in English with Arabic.

Thank.

+3
source share
1 answer

CSS , , node JavaScript AZ (match(/^[a-z]+$/i) ( , ).

true, , - appears-english, CSS .appears-english { font-size: 120% }.

Update

, - ...

JavaScript

var divs = document.getElementsByTagName('div');

for (var i = 0, divsLength = divs.length; i < divsLength; i++) {
  var div = divs[i];

    if (div.firstChild.nodeValue.match(/^[a-z]+$/)) {
       div.className += 'appears-english';
    }  

}

CSS

.appears-english {
   font-size: 170%;  
}

jsFiddle.

, , - , [a-z] \w.

, , , replace() span, appears-english .

+4

Source: https://habr.com/ru/post/1795384/


All Articles