简体   繁体   English

基于font-weight的CSS Selector?

[英]CSS Selector based on font-weight?

Is it possible to create a selector that would identify elements with specific HTML font-weight properties? 是否可以创建一个选择器来识别具有特定HTML字体权重属性的元素?

Something like ( fake example): 像( 假的例子):

div[font-weight^='900']{
    font-family:"HaasGrotDisp55Roman";
}
div[font-weight^='500']{
    font-family:"HaasGrotDisp35Thin";
}

w/ font-face css definitions as: w / font-face css定义为:

@font-face {
    font-family: 'HaasGrotDisp35Thin';
    src: url('fonts/neuehaasgrotdisp-35thin.eot');
}
@font-face {
    font-family: 'HaasGrotDisp55Roman';
    src: url('fonts/neuehaasgrotdisp-55roman.eot');
}

Nope. 不。 Add classes to elements so that you can apply certain font-weight's to those elements. 向元素添加类,以便您可以将某些字体权重应用于这些元素。 Use those same classes for to "identify" elements that have a certain font-weight. 使用这些相同的类来“识别”具有特定字体权重的元素。 That's how CSS works. 这就是CSS的工作原理。

You could do the following: 您可以执行以下操作:

/* Your fonts */
@font-face {
    font-family: 'HaasGrotDisp';
    src: url('fonts/neuehaasgrotdisp-35thin.eot');
    font-weight: 500;
    font-style: normal;
}
@font-face {
    font-family: 'HaasGrotDisp';
    src: url('fonts/neuehaasgrotdisp-55roman.eot');
    font-weight: 900;
    font-style: normal;
}

body { font-family: "HaasGrotDisp" }

h1,h2,h3 { font-weight: 900 }

This minifies it to only one font-family. 这将它缩小为只有一个字体系列。 Simply assign the different weights inside your @font-faces 只需在@ font-faces中指定不同的权重即可

And as for your attribute like query: I would suggest using semantic classes to use it with divs. 至于你的属性,如查询:我建议使用语义类将其与div一起使用。

as far as I know, css selector will work on element name or attributes, but not css. 据我所知,css选择器将处理元素名称或属性,但不是css。 besides, even if it were possible, it would be strongly discouraged to do so. 此外,即使有可能,也会强烈劝阻这样做。 instead you can define class for each font face, and apply class to approriate div's, and search div's with those classes. 相反,你可以为每个字体定义类,并将类应用于approriate div,并使用这些类搜索div。

eg) 例如)


`
    .Haas {
      font-family: '...';
    }
    .Neue {
      font-family: '...';
    }

    ...
    <div class="some_class Haas">....
`

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

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