Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 在类名中使用点(.)设置元素的样式_Css_Class - Fatal编程技术网

Css 在类名中使用点(.)设置元素的样式

Css 在类名中使用点(.)设置元素的样式,css,class,Css,Class,我有这样一个元素 <span class='a.b'> 但是,可能有一些浏览器不支持此功能。是的,您可以。 CSS类名“.a.b”的含义是指向具有CSS名称且带有“a”的元素,而“a”也具有类名“b”,也就是说,这两个类都位于同一个元素中。正如div.cssname使用cssname瞄准div元素一样。这次聚会来得很晚,但您可以使用属性选择器 在您的情况下,要针对class='a.b'元素,可以使用: [class~="a.b"] {...} // or span[class~="

我有这样一个元素

<span class='a.b'>
但是,可能有一些浏览器不支持此功能。

是的,您可以。
CSS类名“.a.b”的含义是指向具有CSS名称且带有“a”的元素,而“a”也具有类名“b”,也就是说,这两个类都位于同一个元素中。正如div.cssname使用cssname瞄准div元素一样。

这次聚会来得很晚,但您可以使用属性选择器

在您的情况下,要针对
class='a.b'
元素,可以使用:

[class~="a.b"] {...}
// or
span[class~="a.b"] {...}

此外,下面是属性选择器的完整列表

属性显示选择器

// Selects an element if the given attribute is present

// HTML
<a target="_blank">...</a>

// CSS
a[target] {...}
// Selects an element if the given attribute value
// exactly matches the value stated

// HTML
<a href="http://google.com/">...</a>

// CSS
a[href="http://google.com/"] {...}
// Selects an element if the given attribute value
// contains at least once instance of the value stated

// HTML
<a href="/login.php">...</a>

// CSS
a[href*="login"] {...}
// Selects an element if the given attribute value
// begins with the value stated

// HTML
<a href="https://chase.com/">...</a>

// CSS
a[href^="https://"] {...}
// Selects an element if the given attribute value
// ends with the value stated

// HTML
<a href="/docs/menu.pdf">...</a>

// CSS
a[href$=".pdf"] {...}
// Selects an element if the given attribute value
// is whitespace-separated with one word being exactly as stated

// HTML
<a href="#" rel="tag nofollow">...</a>

// CSS
a[rel~="tag"] {...}
// Selects an element if the given attribute value is
// hyphen-separated and begins with the word stated

// HTML
<a href="#" lang="en-US">...</a>

// CSS
a[lang|="en"] {...}
//如果给定属性存在,则选择元素
//HTML
//CSS
a[href=”http://google.com/"] {...}
属性包含选择器

// Selects an element if the given attribute is present

// HTML
<a target="_blank">...</a>

// CSS
a[target] {...}
// Selects an element if the given attribute value
// exactly matches the value stated

// HTML
<a href="http://google.com/">...</a>

// CSS
a[href="http://google.com/"] {...}
// Selects an element if the given attribute value
// contains at least once instance of the value stated

// HTML
<a href="/login.php">...</a>

// CSS
a[href*="login"] {...}
// Selects an element if the given attribute value
// begins with the value stated

// HTML
<a href="https://chase.com/">...</a>

// CSS
a[href^="https://"] {...}
// Selects an element if the given attribute value
// ends with the value stated

// HTML
<a href="/docs/menu.pdf">...</a>

// CSS
a[href$=".pdf"] {...}
// Selects an element if the given attribute value
// is whitespace-separated with one word being exactly as stated

// HTML
<a href="#" rel="tag nofollow">...</a>

// CSS
a[rel~="tag"] {...}
// Selects an element if the given attribute value is
// hyphen-separated and begins with the word stated

// HTML
<a href="#" lang="en-US">...</a>

// CSS
a[lang|="en"] {...}
//如果给定的属性值
//包含至少一个所述值的实例
//HTML
//CSS
a[href*=“登录”]{…}
属性以选择器开头

// Selects an element if the given attribute is present

// HTML
<a target="_blank">...</a>

// CSS
a[target] {...}
// Selects an element if the given attribute value
// exactly matches the value stated

// HTML
<a href="http://google.com/">...</a>

// CSS
a[href="http://google.com/"] {...}
// Selects an element if the given attribute value
// contains at least once instance of the value stated

// HTML
<a href="/login.php">...</a>

// CSS
a[href*="login"] {...}
// Selects an element if the given attribute value
// begins with the value stated

// HTML
<a href="https://chase.com/">...</a>

// CSS
a[href^="https://"] {...}
// Selects an element if the given attribute value
// ends with the value stated

// HTML
<a href="/docs/menu.pdf">...</a>

// CSS
a[href$=".pdf"] {...}
// Selects an element if the given attribute value
// is whitespace-separated with one word being exactly as stated

// HTML
<a href="#" rel="tag nofollow">...</a>

// CSS
a[rel~="tag"] {...}
// Selects an element if the given attribute value is
// hyphen-separated and begins with the word stated

// HTML
<a href="#" lang="en-US">...</a>

// CSS
a[lang|="en"] {...}
//如果给定的属性值
//以声明的值开始
//HTML
//CSS
a[href^=“https://]”{…}
属性以选择器结尾

// Selects an element if the given attribute is present

// HTML
<a target="_blank">...</a>

// CSS
a[target] {...}
// Selects an element if the given attribute value
// exactly matches the value stated

// HTML
<a href="http://google.com/">...</a>

// CSS
a[href="http://google.com/"] {...}
// Selects an element if the given attribute value
// contains at least once instance of the value stated

// HTML
<a href="/login.php">...</a>

// CSS
a[href*="login"] {...}
// Selects an element if the given attribute value
// begins with the value stated

// HTML
<a href="https://chase.com/">...</a>

// CSS
a[href^="https://"] {...}
// Selects an element if the given attribute value
// ends with the value stated

// HTML
<a href="/docs/menu.pdf">...</a>

// CSS
a[href$=".pdf"] {...}
// Selects an element if the given attribute value
// is whitespace-separated with one word being exactly as stated

// HTML
<a href="#" rel="tag nofollow">...</a>

// CSS
a[rel~="tag"] {...}
// Selects an element if the given attribute value is
// hyphen-separated and begins with the word stated

// HTML
<a href="#" lang="en-US">...</a>

// CSS
a[lang|="en"] {...}
//如果给定的属性值
//以指定的值结束
//HTML
//CSS
a[href$=”.pdf“]{…}
属性间隔选择器

// Selects an element if the given attribute is present

// HTML
<a target="_blank">...</a>

// CSS
a[target] {...}
// Selects an element if the given attribute value
// exactly matches the value stated

// HTML
<a href="http://google.com/">...</a>

// CSS
a[href="http://google.com/"] {...}
// Selects an element if the given attribute value
// contains at least once instance of the value stated

// HTML
<a href="/login.php">...</a>

// CSS
a[href*="login"] {...}
// Selects an element if the given attribute value
// begins with the value stated

// HTML
<a href="https://chase.com/">...</a>

// CSS
a[href^="https://"] {...}
// Selects an element if the given attribute value
// ends with the value stated

// HTML
<a href="/docs/menu.pdf">...</a>

// CSS
a[href$=".pdf"] {...}
// Selects an element if the given attribute value
// is whitespace-separated with one word being exactly as stated

// HTML
<a href="#" rel="tag nofollow">...</a>

// CSS
a[rel~="tag"] {...}
// Selects an element if the given attribute value is
// hyphen-separated and begins with the word stated

// HTML
<a href="#" lang="en-US">...</a>

// CSS
a[lang|="en"] {...}
//如果给定的属性值
//空格之间是否有一个单词完全相同
//HTML
//CSS
[rel~=“tag”]{…}
属性连字符选择器

// Selects an element if the given attribute is present

// HTML
<a target="_blank">...</a>

// CSS
a[target] {...}
// Selects an element if the given attribute value
// exactly matches the value stated

// HTML
<a href="http://google.com/">...</a>

// CSS
a[href="http://google.com/"] {...}
// Selects an element if the given attribute value
// contains at least once instance of the value stated

// HTML
<a href="/login.php">...</a>

// CSS
a[href*="login"] {...}
// Selects an element if the given attribute value
// begins with the value stated

// HTML
<a href="https://chase.com/">...</a>

// CSS
a[href^="https://"] {...}
// Selects an element if the given attribute value
// ends with the value stated

// HTML
<a href="/docs/menu.pdf">...</a>

// CSS
a[href$=".pdf"] {...}
// Selects an element if the given attribute value
// is whitespace-separated with one word being exactly as stated

// HTML
<a href="#" rel="tag nofollow">...</a>

// CSS
a[rel~="tag"] {...}
// Selects an element if the given attribute value is
// hyphen-separated and begins with the word stated

// HTML
<a href="#" lang="en-US">...</a>

// CSS
a[lang|="en"] {...}
//如果给定的属性值为
//连字符分隔,以所述单词开头
//HTML
//CSS
a[lang |=“en”]{…}

也许您可以扫描这些类的元素,并添加一个可以设置样式的类

例如,使用“a.b”类扫描所有元素,然后添加一个新的“style ab”类或类似的类

我还没有发布任何关于这方面的示例代码,因为人们可能想使用香草Javascript或jQuery,这是一件非常简单的事情


为了澄清这一点,我的游戏框架与OP描述的完全一样,因此翻译可以应用于某些div和span。确定类名不是一种令人讨厌的方法,它只对人们在使用带有短语键的词典时创建标记很有用,比如?firefox 1.5+、Safari 3+和IE 6+会支持它吗?我不确定(因此“可能”)。然而IE6却出人意料地做到了。IE5.x和Opera的早期版本不支持这一点。这似乎根本不起作用。假设我想设置span.a.b(a'span'与类'.a.b')的样式,我该怎么做?您需要用反斜杠转义作为类名一部分的点,因此在本例中:
span.a\.b
。示例:哪个疯狂系统将生成这样的类名?部分重复,但可能回答了以下问题:疯狂系统:类名是属性文件中的键。不同语言的不同属性文件允许基于独立于语言但语义相同的内容进行动态格式化。“什么疯狂的系统会生成这样的类名?”Shopify会..啊。@SLaks-google,facebook、youtube、gmail基本上所有大型网络系统都被否决了,因为你还不明白这个问题。OP没有任何类为“a”或“b”的元素,他正在尝试使用类为“a.b”的元素设置样式。属性间隔选择器可能更适合一般情况,因为元素上可能有其他类别,您不想选择。复合物是什么样的?img[data~=“120”]。识别模板,其中data=“120”和class=“recognition\u template”?请为我们这些需要起点的人添加vanilla JS。否则,您的答案仅限于了解如何“扫描所有元素”的人