是否有一种语法可以解决两个样式表之间CSS类名称的歧义? [英] Is there a syntax to resolve ambiguity in CSS class names between two style sheets?

查看:26
本文介绍了是否有一种语法可以解决两个样式表之间CSS类名称的歧义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有一个HTML页面,该页面可以导入两个样式表,如下所示:

Let's say I have an HTML page that imports two style sheets like so:

<link href="Styles1.css" rel="stylesheet" type="text/css" />
<link href="Styles2.css" rel="stylesheet" type="text/css" />

还假定在上述两个样式表中都出现了具有相同名称的类.

Also assume that a class with the same name appears in both of the above style sheets.

.SomeStyle {font-weight:bold;  } /* in Styles1.css */
.SomeStyle {font-weight:normal;} /* in Styles2.css */

问题:是否存在一种语法,可以将类应用于元素,从而消除使用哪个版本的样式的歧义?

Question: Is there a syntax where I can apply the class to an element in a way that disambiguates which version of the style to use?

例如(伪代码):

<span id="mySpan" class="Styles1.css:SomeStyle">Example</span>

免责声明:我知道更好的解决方案是解决两个样式表之间的名称冲突,但是我主要是出于学术原因.

Disclaimer: I know that a better solution would be to resolve name conflict between the two style sheets, but I am asking mostly for academic reasons.

推荐答案

有没有一种语法可以将类应用于元素,从而消除使用哪个版本的样式?

Is there a syntax where I can apply the class to an element in a way that disambiguates which version of the style to use?

不.后一种样式将前一种样式覆盖为一种计算样式.无法撤消该操作.

No. The latter style overrides the former into one computed style. There is no way to undo that.

您唯一可以做的就是为每个定义附加其他类:

The only thing you could do is attach additional classes to each definition:

.SomeStyle.First {font-weight:bold;  } /* in Styles1.css */
.SomeStyle.Second {font-weight:normal;} /* in Styles2.css */

然后使用

<span id="mySpan" class="SomeStyle Second">Example</span>

这篇关于是否有一种语法可以解决两个样式表之间CSS类名称的歧义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆