gpt4 book ai didi

css - 是否有一种语法可以解决两个样式表之间 CSS 类名称中的歧义?

转载 作者:技术小花猫 更新时间:2023-10-29 12:04:12 25 4
gpt4 key购买 nike

假设我有一个导入两个样式表的 HTML 页面,如下所示:

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

还假设同名类出现在上述两个样式表中。

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

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

例如(伪代码):

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

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

最佳答案

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?

没有。后一种风格将前者覆盖为一种计算风格。无法撤消。

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

.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 - 是否有一种语法可以解决两个样式表之间 CSS 类名称中的歧义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5010074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com