简体   繁体   English

谷歌浏览器中的 Console.log 自定义 fonts

[英]Console.log custom fonts in google chrome

I've been making game which is played in the browsers console, and I'm interested of the possibility of using custom fonts.我一直在制作在浏览器控制台中玩的游戏,我对使用自定义 fonts 的可能性感兴趣。 I'm working with chrome and don't really care about compatibility with other browsers.我正在使用 chrome,并不真正关心与其他浏览器的兼容性。 I know that console.log() can be styled with CSS , but I haven't had any success with trying to get it to work with custom fonts.我知道console.log() 可以使用 CSS 进行样式设置,但我没有成功尝试让它与自定义 fonts 一起使用。

My css looks like this:我的 css 看起来像这样:

@font-face {
  font-family: MyFont;
  src: url(MyFont.woff);
}

and my Js looks like this:我的 Js 看起来像这样:

console.log("%cThis text shoud be styled!", "font-family: MyFont;");

I've allso tried using '':我也尝试过使用'':

console.log("%cThis text shoud be styled!", "font-family: 'MyFont';");

Both are in the same html file in their respective tags (no external css or js files) css on the top and js on the bottom.两者都在各自标签中的同一个 html 文件中(没有外部 css 或 js 文件)顶部的 css 和底部的 js。

Thanks in advance: :)提前致谢: :)

As far as I know you can use a font called "system-ui" to change the text's font.据我所知,您可以使用一种名为“system-ui”的字体来更改文本的字体。 You can't use custom fonts, though.但是,您不能使用自定义 fonts。

console.log("%cThis text should be styled!", "font-family: system-ui");

// This might interest you as well
console.log("%cThis text should be styled!", "font-variant: small-caps");
console.log("%cThis is a custom font style","color: red; font-family:monospace; font-size: 20px");

if you're using google fonts what you could do is:如果你使用谷歌 fonts 你可以做的是:

console.log(`example text`,`@import url('https://fonts.googleapis.com/...'); font-family:'your-font-family','monospace';`)

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

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