【问题标题】:What is the different between [att|=val] and [att~=val] in csscss中[att|=val]和[att~=val]有什么区别
【发布时间】:2018-07-10 08:16:43
【问题描述】:

我很难理解 CSS [att|=val] and [att~=val] 中的这两个不同属性。谁能简单地给我解释一下

谢谢

【问题讨论】:

标签: html css


【解决方案1】:

[attr|=val] 匹配任何形式的val 中的单词,因此[class=div] 将匹配.my-div.div,但不匹配.mydiv

[attr~=val] 匹配val 中的完整单词,因此[class~=div] 将匹配.div,但不匹配.mydiv.my-div

示例:

HTML

<div id="myDiv"></div>
<div id="myDiv2"></div>
<div id="new-div"></div>

CSS

div[id|=myDiv] {
  /* Matches the first div */
}
div[id|=my]{
  matches first two divs
}
div[id|=new]{
  /* Matches second div - the hyphen counts as a word separator */
}
div[id~=Div]{
  /* Matches nothing - "Div" is not a separate word */
}

【讨论】:

  • 1) 是 [attr|=val] 带管道,而不是 [attr=val] 2) “包含”有点模糊,因为存在其他属性选择器,所以在这里非常具体很有帮助匹配包含子字符串的值。
  • 根据MDN,这个答案是不正确的。你把[attr~=val][attr*=val] 混淆了,我想?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-07
  • 2016-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-27
相关资源
最近更新 更多