根据语言更改字体大小

时间:2022-08-14 20:29:35

So i have read a few suggestions with the css language tag, but it seems like everything requires placing the language in the tag in advanced. I am not able to change the html tags around the korean language, it has the same h1 tag as the english. It is because it is a translated version of the same website.

所以我已经阅读了一些css语言标签的建议,但似乎所有内容都需要将语言放在标签中。我无法更改韩语语言的html标签,它与英语具有相同的h1标签。这是因为它是同一网站的翻译版本。

I want to have a different font and font size for the korean version than the english. Can i do this by just knowing the language? I found some other questions dealing with the unicode range that used @font-face { } , for one, I cant figure out what unicode range Korean is, i have tried looking at all the documentation but i just dont comprehend how unicode ranges are calculated and written. Also, i was hoping there was an option like,

我希望韩文版的字体和字体大小与英文不同。我能通过了解语言来做到这一点吗?我发现了一些其他问题涉及使用@ font-face {}的unicode范围,其中一个,我无法弄清楚韩国的unicode范围是什么,我已经尝试查看所有文档,但我只是不理解unicode范围是如何计算的并写。另外,我希望有一个选项,如,

h1{
unicode-range: korean;
font-size: 10px;
}

h1{
unicode-range: english;
font-size 20px;
}

Can this be done?

可以这样做吗?

Thanks!

6 个解决方案

#1


13  

In your case the lang attribute is set on the html tag, so you could style all the elements you need based on that using the rules:

在您的情况下,lang属性在html标记上设置,因此您可以使用以下规则根据需要设置所需的所有元素:

html:lang(en) h1{
    font-size: 20px;
}

html:lang(ko) h1{
    font-size: 10px;
}

Be careful, though, the the :lang pseudo-class is supported only in IE8+. Should you need support in IE7+, your best bet is going for the syntax of this type: a[lang="en"].

但是要小心,只有在IE8 +中才支持:lang伪类。如果您需要IE7 +中的支持,最好的选择是使用此类型的语法:a [lang =“en”]。

#2


4  

You could use the CSS :lang pseudo class if you set the lang attribute in your HTML to alter the style. For example see demo or the following code:

如果在HTML中设置lang属性以更改样式,则可以使用CSS:lang伪类。例如,请参阅演示或以下代码:

CSS

:lang(en) {
    font-size:20px;
}

:lang(fr) {
    font-size:10px;
}

HTML

<p lang="en">Lorem</p>
<p lang="fr">Lorem</p>

#3


2  

This might be helpful: http://billposer.org/Linguistics/Computation/UnicodeRanges.html

这可能会有所帮助:http://billposer.org/Linguistics/Computation/UnicodeRanges.html

You're looking for Hangul which is "The Korean alphabet, also known as Hangul,[nb 1] or Chosongul"

你正在寻找韩文字母“韩文字母,也称为韩文,[nb 1]或Chosongul”

Regards

#4


0  

Change the style sheet on language select

在语言选择上更改样式表

<body onload="set_style_from_cookie()">

//style sheet
<link rel="stylesheet" type="text/css" title="korean"
    href="http://example.com/css/korean.css">
<link rel="alternate stylesheet" type="text/css" title="english"
    href="http://example.com/css/english.css">

//form to select language using button
<form>
<input type="submit"
  onclick="switch_style('korean');return false;"
  name="theme" value="korean Language" id="korean">
<input type="submit"
  onclick="switch_style('english');return false;"
  name="theme" value="english language" id="english">
</form>

//javascript
<script>
// *** TO BE CUSTOMISED ***

var style_cookie_name = "style" ;
var style_cookie_duration = 30 ;

// *** END OF CUSTOMISABLE SECTION ***

function switch_style ( css_title )
{

  var i, link_tag ;
  for (i = 0, link_tag = document.getElementsByTagName("link") ;
    i < link_tag.length ; i++ ) {
    if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) &&
      link_tag[i].title) {
      link_tag[i].disabled = true ;
      if (link_tag[i].title == css_title) {
        link_tag[i].disabled = false ;
      }
    }
    set_cookie( style_cookie_name, css_title,
      style_cookie_duration );
  }
}
function set_style_from_cookie()
{
  var css_title = get_cookie( style_cookie_name );
  if (css_title.length) {
    switch_style( css_title );
  }
}
function set_cookie ( cookie_name, cookie_value,
    lifespan_in_days, valid_domain )
{

    var domain_string = valid_domain ?
                       ("; domain=" + valid_domain) : '' ;
    document.cookie = cookie_name +
                       "=" + encodeURIComponent( cookie_value ) +
                       "; max-age=" + 60 * 60 *
                       24 * lifespan_in_days +
                       "; path=/" + domain_string ;
}
function get_cookie ( cookie_name )
{

    var cookie_string = document.cookie ;
    if (cookie_string.length != 0) {
        var cookie_value = cookie_string.match (
                        '(^|;)[\s]*' +
                        cookie_name +
                        '=([^;]*)' );
        return decodeURIComponent ( cookie_value[2] ) ;
    }
    return '' ;
}
</script>

#5


0  

you could use something similar to:

你可以使用类似的东西:

h1[lang=en] {
  font-size: 10px;
}

h1[lang=kr] {
  font-size: 14px;
}

or if you would like to only specify lang="" once, instead of on every element, you could do

或者如果您只想指定lang =“”一次,而不是每个元素,您可以这样做

#content[lang=en] h1 {

}

#content[lang=en] p {

}

#content[lang=kr] h1 {

}

#content[lang=kr] p {

}

#6


0  

If you're using some dynamic language as server side of your website, you can simply do a dynamic CSS loading based on the Locale.

如果您使用某种动态语言作为网站的服务器端,则可以根据Locale简单地进行动态CSS加载。

E.g. you have, in css folder, the following:

例如。你在css文件夹中有以下内容:

style.css        // this is the default
style_en_US.css
style_ko_KR.css

So you can have a separation of global settings from locale-specific ones and can load the required style dynamically with ease.

因此,您可以将全局设置与特定于语言环境的设置分开,并可以轻松地动态加载所需的样式。

If you have a static HTML page instead, you can have JavaScript to load the CSS dynamically or you can use the

如果你有一个静态HTML页面,你可以让JavaScript动态加载CSS,或者你可以使用

:lang

pseudo-class as pointed by others as well.

其他人也指出了伪阶级。

Whatever solution you choose, remember to keep an eye on browser-compatibility.

无论您选择何种解决方案,请记住密切关注浏览器兼容性。

NOTE: Often it is a better solution to have the user explicitly select his/her preferred locale instead of automatically setting one based on the client's system information.

注意:通常,让用户明确选择他/她的首选区域设置而不是根据客户端的系统信息自动设置区域设置是一种更好的解决方案。

#1


13  

In your case the lang attribute is set on the html tag, so you could style all the elements you need based on that using the rules:

在您的情况下,lang属性在html标记上设置,因此您可以使用以下规则根据需要设置所需的所有元素:

html:lang(en) h1{
    font-size: 20px;
}

html:lang(ko) h1{
    font-size: 10px;
}

Be careful, though, the the :lang pseudo-class is supported only in IE8+. Should you need support in IE7+, your best bet is going for the syntax of this type: a[lang="en"].

但是要小心,只有在IE8 +中才支持:lang伪类。如果您需要IE7 +中的支持,最好的选择是使用此类型的语法:a [lang =“en”]。

#2


4  

You could use the CSS :lang pseudo class if you set the lang attribute in your HTML to alter the style. For example see demo or the following code:

如果在HTML中设置lang属性以更改样式,则可以使用CSS:lang伪类。例如,请参阅演示或以下代码:

CSS

:lang(en) {
    font-size:20px;
}

:lang(fr) {
    font-size:10px;
}

HTML

<p lang="en">Lorem</p>
<p lang="fr">Lorem</p>

#3


2  

This might be helpful: http://billposer.org/Linguistics/Computation/UnicodeRanges.html

这可能会有所帮助:http://billposer.org/Linguistics/Computation/UnicodeRanges.html

You're looking for Hangul which is "The Korean alphabet, also known as Hangul,[nb 1] or Chosongul"

你正在寻找韩文字母“韩文字母,也称为韩文,[nb 1]或Chosongul”

Regards

#4


0  

Change the style sheet on language select

在语言选择上更改样式表

<body onload="set_style_from_cookie()">

//style sheet
<link rel="stylesheet" type="text/css" title="korean"
    href="http://example.com/css/korean.css">
<link rel="alternate stylesheet" type="text/css" title="english"
    href="http://example.com/css/english.css">

//form to select language using button
<form>
<input type="submit"
  onclick="switch_style('korean');return false;"
  name="theme" value="korean Language" id="korean">
<input type="submit"
  onclick="switch_style('english');return false;"
  name="theme" value="english language" id="english">
</form>

//javascript
<script>
// *** TO BE CUSTOMISED ***

var style_cookie_name = "style" ;
var style_cookie_duration = 30 ;

// *** END OF CUSTOMISABLE SECTION ***

function switch_style ( css_title )
{

  var i, link_tag ;
  for (i = 0, link_tag = document.getElementsByTagName("link") ;
    i < link_tag.length ; i++ ) {
    if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) &&
      link_tag[i].title) {
      link_tag[i].disabled = true ;
      if (link_tag[i].title == css_title) {
        link_tag[i].disabled = false ;
      }
    }
    set_cookie( style_cookie_name, css_title,
      style_cookie_duration );
  }
}
function set_style_from_cookie()
{
  var css_title = get_cookie( style_cookie_name );
  if (css_title.length) {
    switch_style( css_title );
  }
}
function set_cookie ( cookie_name, cookie_value,
    lifespan_in_days, valid_domain )
{

    var domain_string = valid_domain ?
                       ("; domain=" + valid_domain) : '' ;
    document.cookie = cookie_name +
                       "=" + encodeURIComponent( cookie_value ) +
                       "; max-age=" + 60 * 60 *
                       24 * lifespan_in_days +
                       "; path=/" + domain_string ;
}
function get_cookie ( cookie_name )
{

    var cookie_string = document.cookie ;
    if (cookie_string.length != 0) {
        var cookie_value = cookie_string.match (
                        '(^|;)[\s]*' +
                        cookie_name +
                        '=([^;]*)' );
        return decodeURIComponent ( cookie_value[2] ) ;
    }
    return '' ;
}
</script>

#5


0  

you could use something similar to:

你可以使用类似的东西:

h1[lang=en] {
  font-size: 10px;
}

h1[lang=kr] {
  font-size: 14px;
}

or if you would like to only specify lang="" once, instead of on every element, you could do

或者如果您只想指定lang =“”一次,而不是每个元素,您可以这样做

#content[lang=en] h1 {

}

#content[lang=en] p {

}

#content[lang=kr] h1 {

}

#content[lang=kr] p {

}

#6


0  

If you're using some dynamic language as server side of your website, you can simply do a dynamic CSS loading based on the Locale.

如果您使用某种动态语言作为网站的服务器端,则可以根据Locale简单地进行动态CSS加载。

E.g. you have, in css folder, the following:

例如。你在css文件夹中有以下内容:

style.css        // this is the default
style_en_US.css
style_ko_KR.css

So you can have a separation of global settings from locale-specific ones and can load the required style dynamically with ease.

因此,您可以将全局设置与特定于语言环境的设置分开,并可以轻松地动态加载所需的样式。

If you have a static HTML page instead, you can have JavaScript to load the CSS dynamically or you can use the

如果你有一个静态HTML页面,你可以让JavaScript动态加载CSS,或者你可以使用

:lang

pseudo-class as pointed by others as well.

其他人也指出了伪阶级。

Whatever solution you choose, remember to keep an eye on browser-compatibility.

无论您选择何种解决方案,请记住密切关注浏览器兼容性。

NOTE: Often it is a better solution to have the user explicitly select his/her preferred locale instead of automatically setting one based on the client's system information.

注意:通常,让用户明确选择他/她的首选区域设置而不是根据客户端的系统信息自动设置区域设置是一种更好的解决方案。