简体   繁体   English

我可以使用CSS“ unicode-range”在整个(第三方)页面上指定字体吗?

[英]Can I use CSS “unicode-range” to specify a font across an entire (third party) page?

I've never become fluent with CSS but I don't think I had this situation before. 我从不流利使用CSS,但我认为以前没有这种情况。

I'm thinking of using stylish to add CSS to a third-party site over which I have no direct control. 我正在考虑使用时尚的方式将CSS添加到我无法直接控制的第三方站点。 So the HTML and CSS is not really set up for the kind of customizations I want to do. 因此,HTML和CSS并不是针对我想做的自定义设置的。

The site I wish to tweak doesn't allow good control over fonts but some of its pages (user created) make a lot of use of some exotic Unicode ranges (eg. Khmer) that my OS/browser combination choose a terrible font for: 我希望调整的站点不允许很好地控制字体,但是它的某些页面(用户创建)大量使用了一些奇怪的Unicode范围(例如高棉语),而我的OS /浏览器组合选择了一种糟糕的字体:

two muppets

Can I make a CSS rule that will apply to all text in a page that falls within a certain Unicode range to set it to a known good font, without delving into the structure of the page HTML/DOM? 我可以制定一个CSS规则,将其应用于页面中属于Unicode范围内的所有文本,以将其设置为已知的良好字体,而无需研究页面HTML / DOM的结构吗?

(Or is unicode-range only for doing something different with webfonts? (或者unicode-range仅用于对webfonts做一些不同的事情?

The answer is yes in most browsers 在大多数浏览器中答案是肯定的

MDN - Unicode Range MDN-Unicode范围

The unicode-range CSS descriptor sets the specific range of characters to be downloaded from a font defined by @font-face and made available for use on the current page. Unicode代码范围的CSS描述符设置了从@ font-face定义的字体中下载的特定字符范围,并可以在当前页面上使用。

Example: 例:

@font-face {
  font-family: 'Ampersand';
  src: local('Times New Roman');
  unicode-range: U+26;
}

Support: CanIUse.com 支持: CanIUse.com

Also see this Article 另请参阅这篇文章

unicode-range(s) can be used to specify which specific set (or range) of characters you want to be downloaded from a font in an attempt to save bandwidth. unicode-range(s)可用于指定要从字体下载哪个特定的字符集(或范围),以节省带宽。 See here: Mozilla unicode-range info 参见此处: Mozilla Unicode范围信息

Without seeing the actual CSS you could attempt to just force a different font to be used completely by doing something such as declaring 在没有看到实际CSS的情况下,您可以尝试执行诸如声明等操作来强制完全使用其他字体

body{font-family: arial,sans-serif;}    

or adding !important (which I would avoid under any normal circumstance) if the other fonts refuse to give way eg 或添加!important(在其他正常情况下我会避免的),如果其他字体拒绝让步,例如

body{font-family: arial,sans-serif !important;}

If you can bypass using the original font faces then the unicode-ranges will cease to be important. 如果您可以绕过使用原始字体的样式,则unicode范围将不再重要。 Watch out for things like icon-fonts though as removing those may make certain symbols/graphics disappear. 请注意像图标字体之类的内容,尽管删除它们可能会使某些符号/图形消失。

Hope that helps. 希望能有所帮助。

Sorry I rather misunderstood your question - thought you wanted rid of the existing unicode fonts altogether. 抱歉,我想误解了您的问题-以为您希望完全摆脱现有的unicode字体。

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

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