<div class="container">
<h3>7 Types Of Attribute Selectors</h3>
<a href="#selector_one">- [attr]</a>
<a href="#selector_two">- [attr=value]</a>
<a href="#selector_three">- [attr~=value]</a>
<a href="#selector_four">- [attr|=value]</a>
<a href="#selector_five">- [attr^=value]</a>
<a href="#selector_six">- [attr$=value]</a>
<a href="#selector_seven">- [attr*=value]</a>
</div>
<div class="selector" id="selector_one">
<h2>[attr] - Attribute Exsist</h2>
<a href="http://example.com" target="_blank">I'm External Link😎</a>
<a href="#internal">I'm internal link🙄</a>
</div>
<div class="selector" id="selector_two">
<h2>[attr = value]</h2>
<a href="https://example.org" target="_blank">Yes, I'm😎</a>
<a href="#internal">Oops, I'm not😣</a>
</div>
<div class="selector" id="selector_three">
<h2>[attr~=value]</h2>
<img src="//placehold.it/150/150" alt="abstract art">
<img src="//placehold.it/150/150" alt="something to eat">
<img src="//placehold.it/150/150" alt="athlete starting a new sport">
</div>
<div class="selector" id="selector_four">
<h2>[Attr|=value]</h2>
<ul>
<li data-years="1800-1900">The 19th Century</li>
<li data-years="1900-2000">The 20th Century</li>
<li data-years="2000-2100">The 21st Century</li>
</ul>
</div>
<div class="selector" id="selector_five">
<h2>[attr^=value]</h2>
<img src="//placehold.it/150/184/abstract" alt="artistic pattern">
<img src="//placehold.it/150/184/food" alt="a healthy meal">
<img src="//placehold.it/150/184/sports" alt="Arthur Miller">
</div>
<div class="selector" id="selector_six">
<h2>[attr$=value]</h2>
<a href="example.pdf" target="_blank">I'm pdf file😉</a>
<a href="#internal">hm, I'm a link😒</a>
</div>
<div class="selector" id="selector_seven">
<h2>[attr*=value]</h2>
<img src="//placehold.it/150/150" alt="abstract art">
<img src="//placehold.it/150/150" alt="something to eat">
<img src="//placehold.it/150/150" alt="athlete starting a new sport">
</div>
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;500;600;700&family=Raleway:wght@200;300;400;500;600;700&display=swap");
* {
background: #000;
color: #fff;
font-size: 1.5rem;
font-family: "Raleway", sans-serif;
}
h3,
h2 {
font-size: 3rem;
background-image: linear-gradient(25deg, #002657, #662b54, #a9264f, #ec004a);
padding: 1em;
font-weight: 300;
}
h2 {
font-size: 2rem;
}
li {
list-style: none;
}
.container a {
text-decoration: none;
display: block;
background-image: linear-gradient(25deg, #002657, #662b54, #a9264f, #ec004a);
padding: 0.5em;
width: min(50%, 500px);
margin: 0 auto;
}
.selector {
text-align: center;
padding: 100px 0 0 0;
}
@media (max-width: 700px) {
* {
font-size: 1rem;
}
h3 {
font-size: 2rem;
}
}
/* 7 types of selectors */
/* attribute exists */
#selector_one [target] {
color: orange;
}
/* [attr=value] */
#selector_two a[href="https://example.org"]
{
color: lightgreen;
}
/* [attr~=value] */
#selector_three img[alt~="art"] {
border: 3px solid lightgreen;
}
/* attr|=value */
#selector_four li[data-years|="1900"] {
/* data-years attribute starts with 1900 as the only value or first in a dash-separated list */
color: red;
}
/* [attr^=value] */
#selector_five img[alt^="art"] {
/* alt attribute starts with the value "art" */
border: 3px solid #e18728;
}
/* attr$=value */
#selector_six [href$="pdf"] {
background: white;
color: brown;
text-decoration: none;
padding: 0.5em;
border-radius: 2em;
display: inline-block;
}
/* [attr*=value] */
#selector_seven img[alt*="art"] {
border: 3px solid lightgreen;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.