Getting Cray / On Fleek
By using :target
and ~
we can do some pretty ridiculous things without touching Javascript. In this pen, we are using :target
to trigger different state-related styles.
At the top of this pen, there are <a>
elements. Their only purpose is being used as targets.
<a id="s1" class="s"></a>
<a id="s2" class="s"></a>
...
Using their :target
state, we can then select and style anything else on the page.
Moving the main content area over -300%
to reveal this fourth section.
#s4:target ~ main {
left: -300%;
}
Changing the background color and image:
#s4:target ~ #background {
background-image: url(http://lorempixel.com/g/400/150/city/4/);
background-color: #265273;
}
Changing the progress bar width:
#s4:target ~ #progress {
width: 50%;
}
Styling the fourth thumbnail as active:
#s4:target ~ .thumbs li:nth-child(4) a {
opacity: 1;
width: 80px;
height: 60px;
box-shadow: 0px 0px 0px 1px rgba(255, 255, 255, 0.1);
}
Showing the appropriate previous link and making it say the right thing:
#s4:target ~ .prevnext li[class*="p4"] {
display: block;
float: left;
}
#s4:target ~ .prevnext li[class*="p4"] a:after {
content: "Prev";
}
Showing the appropriate next link and making it say the right thing:
#s4:target ~ .prevnext li[class*="n4"] {
display: block;
float: right;
}
#s4:target ~ .prevnext li[class*="n4"] a:after {
content: "Next";
}