天天看点

html span 字体位置,html – 如何强制span在CSS中使用父字体系列

您可以使用.parent *选择所有子元素,然后将font-family设置为继承.这将有效地覆盖子元素字体并强制所有子元素继承最接近的父元素字体的值.

.parent {

font-family: tahoma;

}

.child {

font-family: cursive, geneva;

}

.parent * {

font-family: inherit;

}

Text

如果你只想定位.child元素,你显然会将选择器更改为.parent .child.

根据您要实现的目标,还值得一提的是,您可以使用直接子选择器>,以便仅定位直接子项:.parent> *.

.parent {

font-family: tahoma;

}

.descendant {

font-family: cursive, geneva;

}

.parent > * {

font-family: inherit;

}

Direct child. Not a direct child