--- title: Attribute selectors slug: Web/CSS/Attribute_selectors tags: - Attribute - Attribute selectors - CSS - CSS 3 - CSS 3 Attribute selectors - CSS Attributes - Identifying Elements - Identifying Nodes - Selecting Elements - Selectors - محدد الخاصية - محددات translation_of: Web/CSS/Attribute_selectors ---
يطابق محدد خاصية CSS عناصر تستند إلى وجود أو قيمة لخاصية معينة.
/* <a> elements with a title attribute */ a[title] { color: purple; } /* <a> elements with an href matching "https://example.org" */ a[href="https://example.org"] { color: green; } /* <a> elements with an href containing "example" */ a[href*="example"] { font-size: 2em; } /* <a> elements with an href ending ".org" */ a[href$=".org"] { font-style: italic; }
[attr]
[attr=value]
[attr~=value]
[attr|=value]
[attr^=value]
[attr$=value]
[attr*=value]
[attr operator value i]
a { color: blue; } /* "#" الروابط الداخلية ، تبدأ بـ*/ a[href^="#"] { background-color: gold; } /* URL روابط مع "example" في أي مكان في عنوان */ a[href*="example"] { background-color: silver; } /* URL روابط "غير حساسة" في أي مكان في عنوان ، بغض النظر عن الكتابة بحرف كبير*/ a[href*="insensitive" i] { color: cyan; } /* ".org"الروابط التي تنتهي بـ */ a[href$=".org"] { color: red; }
<ul> <li><a href="#internal">Internal link</a></li> <li><a href="http://example.com">Example link</a></li> <li><a href="#InSensitive">Insensitive internal link</a></li> <li><a href="http://example.org">Example org link</a></li> </ul>
{{EmbedLiveSample('Links')}}
/* All divs with a `lang` attribute are bold. */ div[lang] { font-weight: bold; } /* All divs in US English are blue. */ div[lang~="en-us"] { color: blue; } /* All divs in Portuguese are green. */ div[lang="pt"] { color: green; } /* All divs in Chinese are red, whether simplified (zh-CN) or traditional (zh-TW). */ div[lang|="zh"] { color: red; } /* All divs with a Traditional Chinese `data-lang` are purple. */ /* Note: You could also use hyphenated attributes without double quotes */ div[data-lang="zh-TW"] { color: purple; }
<div lang="en-us en-gb en-au en-nz">Hello World!</div> <div lang="pt">Olá Mundo!</div> <div lang="zh-CN">世界您好!</div> <div lang="zh-TW">世界您好!</div> <div data-lang="zh-TW">?世界您好!</div>
{{EmbedLiveSample('Languages')}}
مواصفات | الحالة | تعليق |
---|---|---|
{{SpecName('CSS4 Selectors', '#attribute-selectors', 'attribute selectors')}} | {{Spec2('CSS4 Selectors')}} | يضيف المعدل ل ASCII اختيار قيمة خاصية غير حساسة لحالة الأحرف |
{{SpecName('CSS3 Selectors', '#attribute-selectors', 'attribute selectors')}} | {{Spec2('CSS3 Selectors')}} | |
{{SpecName('CSS2.1', 'selector.html#attribute-selectors', 'attribute selectors')}} | {{Spec2('CSS2.1')}} | التعريف الأولي |
{{Compat("css.selectors.attribute")}}