简体   繁体   English

基于字体系列的 CSS 对齐

[英]CSS align based on font-family

I've set the font-family of a div to "Vermin Vibes", fantasy, serif;我已将divfont-family设置为"Vermin Vibes", fantasy, serif; , so that if the first font is not avaiable, the browser will automatically use the next one , 这样如果第一种字体不可用,浏览器将自动使用下一种

#myheader {
    position: sticky;
    top: 1rem;

    text-align: center;

    font-family: "Vermin Vibes", fantasy, serif;
    font-size: 6rem;
}

The problem is that when the font changes family , it changes his size and his alignment from the top of the screen...问题是,当字体更改family 时,它会从屏幕顶部更改其大小和对齐方式......

How can I set top and font-size to change when font-family changes?font-family更改时,如何设置topfont-size来更改?

CSS is only concerned with how your content is styled. CSS 只关心内容的样式。 You might have fonts dependent on the content, so a solution would be modifying your HTML since HTML is for defining the actual content of the page.您可能拥有依赖于内容的字体,因此解决方案是修改您的 HTML,因为 HTML 用于定义页面的实际内容。 I think this would be more related to investigated browser compatibility for your client.我认为这与为您的客户端调查的浏览器兼容性更相关。

By the time a fallback font-family is determined, the content has already loaded.当确定后备字体系列时,内容已经加载。 So you'll need Javascript for that.所以你需要Javascript。

So determine where the processing for CSS styles will happen before it is compiled and evaluated by your browser.因此在浏览器编译和评估 CSS 样式之前,确定处理 CSS 样式的位置。 You may have to extract the font-family using Javascript and set styles conditionally if you are using plain CSS without a preprocessor.如果您使用没有预处理器的纯 CSS,您可能必须使用 Javascript 提取字体系列并有条件地设置样式。

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

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