visit
:root {
--background: #888;
}
:root {
--background: #888;
}
div {
background-color: var(--background);
}
/* the code above is equal to */
div {
background-color: #888;
}
div {
--background: #888;
backgorund-color: var(--background);
}
div {
--background: ;
background-color: var(--background, blue);
}
.item:nth-last-of-type(2) {
background: yellow;
}
the page content is declared as a grid, and each container in the grid is declared with a .item class. With a pseudo-selector
:nth-child
or :nth-last-of-type
you evaluate the condition of all the containers with a background: yellow
. Having said that, we can start playing with the number of yellow containers and its position, so if we write this :nth-last-of-type(3n)
instead of :nth-last-of-type(2)
and we look for the code displayed, we are going to find out that the number of yellow containers changed as its position. Now, as you can see, we can find a yellow container every 3 containers with no background-color. Keep in mind, that we are not counting the article containers with border colors of red and blue. .item:nth-child(3n) {
background: yellow;
}
.item:nth-last-of-type(6n + 2) {
background: yellow;
}
This content has been created with pure CSS only. Some of you would thing this is not possible, and you need to use JavaScript. Take a look in the Codepen HTML and JavaScript code editors, and see what's there: NOTHING! That's right, with pure CSS you can make a counter using the property
counter-reset
. The value for the counter reset starts with the name you want to give to the counter, in this case the name of the counter is "contador"
counter-reset: contador
and then, you have to give it a starting number, in this case: 100 counter-reset: contador 100;
.body {
counter-reset: contador 100;
animation: contar 30s forwards alternate infinite;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
&::after {
content: counter(contador);
font-size: 16em;
}
}
The next part of the code starts animating the counter with a
@keyframe
rule, which has to have an animation name ("contar").@keyframes contar {
@for $i from 100 through 1 {
#{$i}% {
counter-increment: contador #{-$i};
background: hsl($i * 3.6,100,40);
color: #fff;
}
}
}
From here we are going to give it a property named
counter-increment
which has to start with the name of the counter given and the counter instruction of start decreasing the counter one by one declared using the next code #{-$i}
.As you can see, create animating counters is very straight forward. This is one of my favorites CSS properties and it was a surprise for me when I learned it.So far, we have reviewed three CSS properties that some new developers might don't know, and I'm sure there's a lot undiscovered possibilities out there waiting for us to learn them from the most darkest and thrilling levels of the CSS world. Once you start exploring the deepest areas of CSS, you can't start and then, you will find out there's infinite possibilities to be creative and could improve your web developing skills.This article has been made by me, inspired by an Edteam conference.I want to thank you for taking your time to read this article. Here is my Github profile, feel free to give your feedback. Emilio Contreras.