[attribute |= value] 与 [attribute ^= value] 的联系与区别:

一、联系:

1. 两个选择器的 attribute 属性值等于 value 时都可以匹配

<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="test">The third div element.</div>
<p class="test">This is some text in a paragraph.</p>
<div class="vue">vuevuevuevue.</div>
div[class^="test"]{
background:#ff0;
}
div[class|="vue"]{
background:#0f0;
}

2. 两个选择器的 attribute 属性值以 value 开头且后面都跟上"-"时都可以匹配

<!-- html 中 class 名改变 -->
<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="test-test">The third div element.</div>
<p class="test">This is some text in a paragraph.</p>
<div class="vue-test">vuevuevuevue.</div>
/* css 不变 */
div[class^="test"]{
background:#ffff00;
}
div[class|="vue"]{
background:#00ff00;
}

它们的结果不变:

二、区别:

1. 两个选择器的 attribute 属性值以 value 开头且后面都不跟上"-",而是随意添上其它字母时,[attribute ^= value] 可以匹配,而 [attribute |= value] 不能匹配

<!-- html 中 class 名改变 -->
<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="testss">The third div element.</div>
<p class="test">This is some text in a paragraph.</p>
<div class="vuess">vuevuevuevue.</div>
/* css 不变 */
div[class^="test"]{
background:#ffff00;
}
div[class|="vue"]{
background:#00ff00;
}

结果也改变:

其它情况下,比如后面添加 "_"等其它符号,和上面一样的结果。

总结:

1. [attribute ^= value] 可以同 attribute 值等于 value,或者 attribute 值以 value 开头后面跟任意字符的情况匹配;

2. [attribute |= value] 可以同 attribute 值等于 value,或者 attribute 值以 value 开头且后面只能紧跟 "-" 字符的情况匹配;

3. 可以说 [attribute |= value] 限定跟严格。只要 [attribute |= value] 能匹配到的情况,[attribute ^= value] 都能匹配到。[attribute |= value] 是 [attribute ^= value] 的"子集"。


[attribute ~= value] 与 [attribute *= value] 的联系与区别:

一、联系:

1. 两个选择器的 attribute 属性值等于 value 时都可以匹配

<div class="test">这是第一个 div 元素。</div>
<div class="second">这是第二个 div 元素。</div>
<p class="test">这是段落中的文本。</p>
div[class*="test"]{
background:#ff0;
}
p[class~="test"]{
background:#0ff;
}

2. 两个选择器的 attribute 属性值包含一个 value 单词时都可以匹配

<!-- html 中 class 名改变 -->
<div class="test ss">这是第一个 div 元素。</div>
<div class="second">这是第二个 div 元素。</div>
<p class="test ss">这是段落中的文本。</p>
/*  css 不变 */
div[class*="test"]{
background:#ff0;
}
p[class~="test"]{
background:#0ff;
}

结果也不变:

二、区别:

1. [attribute ~= value] 选择器的 attribute 属性值 value 后面跟上其它的字符时不能匹配;而[attribute *= value] 选择器的 attribute 属性值 value 后面跟上其它的字符时能匹配;

<!-- html 中 class 名改变 -->
<div class="testss">这是第一个 div 元素。</div>
<div class="second">这是第二个 div 元素。</div>
<p class="testss">这是段落中的文本。</p>
/* css 不变 */
div[class*="test"]{
background:#ff0;
}
p[class~="test"]{
background:#0ff;
}

结果改变:

2. 不仅如此,[attribute *= value] 选择器 attribute 的值 value 的在前面或后面添加任意字符都能匹配,只要有 value 这个字符串就行:

<div class="sstestss">这是第一个 div 元素。</div>
<div class="second">这是第二个 div 元素。</div>
<p class="testss">这是段落中的文本。</p>
div[class*="test"]{
background:#ff0;
}
p[class~="test"]{
background:#0ff;
}

总结:

1. [attribute ~= value] 可以同 attribute 值等于 value,或者 attribute 值有 value 这个单词就能匹配;

2. [attribute *= value] 可以同 attribute 值等于 value,或者 attribute 值有 value 这个单词,或者在 attribute 值的前后添加任意字符,只要其中包含 value 这个字符串都能匹配;

3. 可以说 [attribute ~= value] 限定更严格。只要 [attribute ~= value] 能匹配到的情况,[attribute *= value] 都能匹配到。[attribute ~= value] 是 [attribute *= value] 的"子集"。

[attribute |= value] 与 [attribute ^= value],[attribute ~= value] 与 [attribute *= value] 的联系与区别的更多相关文章

  1. [WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored (webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')

    WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored (webxml attribu ...

  2. JSP中,EL表达式向session中取出一个attribute和JSP脚本访问session取出一个attribute,写法有何不同?(转自百度知道)

    EL表达式使用起来会更简洁,假如session中有一个属性A(attrA),那么EL和jsp脚本取值的方式如下: EL表达式:${ sessionScope.attrA } JSP脚本:<%=s ...

  3. [C#] 剖析 AssemblyInfo.cs - 了解常用的特性 Attribute

    剖析 AssemblyInfo.cs - 了解常用的特性 Attribute [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5944391.html 序 ...

  4. Unity中使用Attribute

    Attribute是c#的语言特性 msdn说明如下: The Attribute class associates predefined system information or user-def ...

  5. 理解Attribute

    注:本文转载自http://kb.cnblogs.com/page/87531/ Attribute与Property 的翻译区别 Attribute 一般译作“特性”,Property 仍然译为“属 ...

  6. C#基础---Attribute(标签) 和 reflect(反射) 应用

    1.Attribute的定义与作用: 公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法和属性等.Attributes和Micros ...

  7. Attribute和自定义Property

    property(属性) attribute(特性) property和attribute的同步 id href value class/className 旧IE的趣事 attribute作为DOM ...

  8. Attribute

    Attribute介绍 咱们来说Attribute,他是一个类,所以自定义的Attribute都是继承自System.Attribute,一般命名的时候都是以Attribute结尾.在使用的时候我们可 ...

  9. 通过声明Attribute属性改变不同类的输出效果

    ConsoleApplication--控制台应用程序 首先创建基类: using System; using System.Collections.Generic; using System.Lin ...

  10. C#学习笔记 -- Attribute

    学习参考: http://www.cnblogs.com/dudu/articles/4449.html http://www.cnblogs.com/anytao/archive/2007/04/1 ...

随机推荐

  1. ES6常用七大特性

    ES6可谓是对JS语言的一个颠覆性改变,增加了Module改善JS一直被诟病的模块化.Promise解决异步函数的回调地狱.Class的面相对象编程... 在学习ES6的过程中,大家或多或少都有看过阮 ...

  2. CUBA-Platform将全面助力中国开发者

    关注CUBA的伙伴们,你们好! 今天我们有新的进展告诉大家. 九月十五日到十六日CUBA平台事业部负责人(同时也是Haulmont公司合伙人)专程来到中国与CUBA中国团队进行了两天时间的交流.讨论. ...

  3. javascript图形动画设计--以简单正弦波轨迹移动

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. C# 过滤sql特殊字符串方法

    1. /// <summary>    /// 过滤不安全的字符串    /// </summary>    /// <param name="Str" ...

  5. Restful的优势

    1. 轻量,直接基于http,不在需要任何别的诸如消息协议.get/post/put/delete为CRUD操作2. 面向资源,一目了然,具有自解释性.3. 数据描述简单,一般以xml,json做数据 ...

  6. nodejs简易代理服务器

    直接代码: var http = require('http') var proxy = http.createServer(function (request, response) { var op ...

  7. "类工厂模式"改写SqlHelper

    看到标题您一定很疑惑,23种经典设计模式什么时候多了一个"类工厂模式",稍等,请听我慢慢道来. 实践是检验真理的唯一途径.最近用了"类工厂模式"改写了我公司的S ...

  8. Oracle中常用的命令,随着学习进度总结

    原创作品,欢迎转载,转载请在文章显眼位置注明出处:https://www.cnblogs.com/sunshine5683/p/10016569.html 开始之前先注意:在linux中切换到sqlp ...

  9. Java 运行时数据区域

    1. 整体分类 程序计数器 虚拟机栈 本地方法栈 Java 堆 方法区 运行时常量池 直接内存 2. 程序计数器 每个线程一个计数器,线程的私有内存 指向的是字节码的内存地址? 如果线程执行的是 Ja ...

  10. 中南月赛 B题 Scoop water

    Problem B: Scoop water Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 261  Solved: 57[Submit][Status ...