简体   繁体   English

将font-family设置为CSS中的特定符号

[英]Set font-family to specific symbols in CSS

On my website i use non standard cyrillic font. 在我的网站上,我使用非标准的西里尔字体。 It looks well but it have problems with some special symbols, for example - quotes (for some reason opening and ending quote look different). 它看起来很好,但它有一些特殊符号的问题,例如 - 引号(由于某种原因,开头和结尾引用看起来不同)。

I would like to set font-family for specific symbols using CSS. 我想使用CSS为特定符号设置font-family。 Is it possible? 可能吗?

You can manage this using a unicode range @font-face rule 您可以使用unicode range @font-face规则来管理它

MDN Reference MDN参考

I'm unsure as to how well this demo will work in a Snippet as it will depend on you have the designated font installed. 我不确定这个演示在Snippet中的效果如何,因为它取决于你是否安装了指定的字体。 However, in general, it's something like this: 但是,一般来说,它是这样的:

 @font-face { font-family: 'Algerian'; src: local('Algerian'); unicode-range: U+022-026; } div { font-size: 4em; font-family: Algerian, sans-serif; } div { text-align: center; } p { font-size: 72px; } 
 <div> <p>" Lorem & Ipsum "</p> </div> 

In this instance I've applied the rule to open & closed quotes and the ampersand. 在这个例子中,我已经将规则应用于打开和关闭的引号和&符号。

Support : CanIUse.com 支持CanIUse.com

For Firefox though: 对于Firefox虽然:

Support can be enabled in Firefox using the layout.css.unicode-range.enabled flag 可以使用layout.css.unicode-range.enabled标志在Firefox中启用支持

If you want to change your symbols to a new font then you'll have to wrap them in a tag and assign a class... 如果要将符号更改为新字体,则必须将它们包装在标记中并指定类...

in your CSS add a class for the font 在CSS中为字体添加一个类

.symbol {
  font-family: Arial;
}

Then in your HTML you will need to use this class on your symbols... 然后在您的HTML中,您需要在符号上使用此类...

    <p>Jesse Jackson? Do you even... ah, I see you have a telephone at least. You know that blinking thing I've been calling you on? 
<i class="symbol">"<i>I will break this, I will BREAK THIS.<i class="symbol">"<i> </p>

If the problem is only for quotes? 如果问题仅针对报价?

You could set the :before and :after pseudo for a <blockquote></blockquote> , which could be set to a icon font. 您可以为<blockquote></blockquote>设置:before:after伪,可以设置为图标字体。 Perhaps fontawesome? 也许真的很棒?

 blockquote { position: relative; padding: 1em 2em; } blockquote:before, blockquote:after { position: absolute; font-family: FontAwesome; } blockquote:before { content: "\\f10d"; left: -1em } blockquote:after { content: "\\f10e"; right: -1em } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" type="stylesheet"> <blockquote>Jesse Jackson? Do you even... ah, I see you have a telephone at least. You know that blinking thing I've been calling you on? I will break this, I will BREAK THIS. Damn druggie idiot. Is this what you've been doing the whole time I've been trying to reach you?</blockquote> 

you can use easily like 你可以轻松使用

.custom-font{
 font-family:any
}

and then 然后

<div>hello there <span class='custom-font'>i am custom</span> but i am not</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM