In CSS there are a few ways of addressing different elements. (I am going do use div
elements in the following example.)
Classes - div.main {
IDs - #id-name {
Element - div {
Let's say I'm making a simple animation, and I want to make a p
element spin.
p {
text-align:center;
font-size:40px;
}
#spinner {
animation-name:spin;
animation-duration:03s;
animation-iteration-count:infinite;
animation-timing-function:linear;
}
@keyframes spin {
from {
transform:rotateY(0deg);
} to {
transform:rotateY(360deg);
}
}
<p id="spinner">Hello, world!</p>
What would've been the difference if I would've included all of the animation
parts in the p
address where I made the text bigger and centered, or used a class such as p.main
instead of an id
called spinner
? Is there a difference, or is it just preference?
<p>Thanks!</p>