css - CSS 中的 [x* ="y"] 和 [x^ ="y"] 是什么意思?

标签 css css-selectors

我想知道在 css 中创建类时 * 和 ^ 的含义是什么?

例如:

[class*="sample-"]

[class^="sample-"]

最佳答案

*= 表示查找类属性中某处存在文本“sample-”的所有元素。例如:

<style>
    [class*="sample-"] {}
</style>

<p class="asdsadsample-adas">Matches</p>
<p class="smple-">Doesn't match</p>

^= 这意味着查找 class 属性以文本“sample-”开头的所有元素。例如

<style>
    [class^="sample-"] {}
</style>

<p class="sample-blah">Matches</p>
<p class="ssample-blah">Doesn't match</p>

关于css - CSS 中的 [x* ="y"] 和 [x^ ="y"] 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15285700/

相关文章:

css - Opera box-sizing 不适用于 textarea with flex

javascript - 在 pageinit 上使用 jQuery Mobile 触发点击

css - 嵌套 Sass 不工作?

html - 如何为表格中特定数量的行着色?

css - 什么时候在 CSS 中使用 `>` 标志?

python - selenium.common.exceptions.InvalidSelectorException 与 "span:contains(' 字符串')”

javascript - 我可以使用这段代码来设置 jQuery 中两个元素的高度吗?

html - 如何在 CSS 中旋转 div 中的文本以使我的数字看起来正确(我已经旋转了 div 本身只是想让数字旋转))

javascript - 打开另一个 Filtrify 面板时如何关闭?

css - 通配符 * 在 CSS 中用于类