問題描述
我在這樣的文件中遇到了一個 css 選擇器:
I encountered a css selector in a file like this:
#contactDetails ul li a, a[href^=tel] {....}
推薦答案
這樣的抑揚符^"在 CSS 中沒有明確的含義.兩字符運算符^="可用于屬性選擇器.通常,[attr^=val]
是指那些具有 attr
屬性且值以 val
開頭的元素.
The circumflex character "^" as such has no defined meaning in CSS. The two-character operator "^=" can be used in attribute selectors. Generally, [attr^=val]
refers to those elements that have the attribute attr
with a value that starts with val
.
因此,a[href^=tel]
指的是具有 href
屬性且值以 <開頭的此類 a
元素代碼>電話代碼>.這可能是為了將電話號碼鏈接與其他鏈接區(qū)分開來;這還不夠,因為選擇器也匹配例如<a href="tel.html">...</a>
但它可能只匹配以 tel:
作為協(xié)議的鏈接部分.所以 a[href^="tel:"]
會更安全.
Thus, a[href^=tel]
refers to such a
elements that have the attribute href
with a value that starts with tel
. It is probably meant to distinguish telephone number links from other links; it’s not quite adequate for that, since the selector also matches e.g. <a href="tel.html">...</a>
but it is probably meant to match only links with tel:
as the protocol part. So a[href^="tel:"]
would be safer.
這篇關(guān)于選擇元素時在css中使用的插入符號^是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!