问题
how you use $ in css
[http://codepen.io/jlong/pen/KBhDf][1]
in the above mentioned link on the 3rd line $heartbeat-size: 10px; I wanted to know how to use this element in the style sheet.
回答1:
To answer your question, here is the processed CSS
result of the scss
in your pen:
@-webkit-keyframes heartbeat {
0% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
14% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
28% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
42% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
70% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
}
@-moz-keyframes heartbeat {
0% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
14% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
28% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
42% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
70% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
}
@-o-keyframes heartbeat {
0% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
14% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
28% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
42% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
70% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
}
@keyframes heartbeat {
0% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
14% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
28% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
42% {
-moz-transform: rotate(45deg) scale(1.3);
-ms-transform: rotate(45deg) scale(1.3);
-webkit-transform: rotate(45deg) scale(1.3);
transform: rotate(45deg) scale(1.3);
}
70% {
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
}
body {
text-align: center;
padding: 50px;
}
/* Styles for old versions of IE */
.heartbeat {
font-family: sans-serif;
font-weight: 100;
}
/* :not(:required) hides this rule from IE9 and below */
.heartbeat:not(:required) {
-webkit-animation: heartbeat 1300ms ease 0s infinite normal;
-khtml-animation: heartbeat 1300ms ease 0s infinite normal;
-moz-animation: heartbeat 1300ms ease 0s infinite normal;
-ms-animation: heartbeat 1300ms ease 0s infinite normal;
-o-animation: heartbeat 1300ms ease 0s infinite normal;
animation: heartbeat 1300ms ease 0s infinite normal;
display: inline-block;
position: relative;
overflow: hidden;
text-indent: -9999px;
width: 36px;
height: 36px;
-moz-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
-webkit-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-webkit-transform-origin: 50% 50%;
transform-origin: 50% 50%;
}
.heartbeat:not(:required):after, .heartbeat:not(:required):before {
position: absolute;
content: "";
background: #e87;
}
.heartbeat:not(:required):before {
-moz-border-radius-topleft: 12px;
-webkit-border-top-left-radius: 12px;
border-top-left-radius: 12px;
-moz-border-radius-bottomleft: 12px;
-webkit-border-bottom-left-radius: 12px;
border-bottom-left-radius: 12px;
top: 12px;
left: 0;
width: 36px;
height: 24px;
}
.heartbeat:not(:required):after {
-moz-border-radius-topleft: 12px;
-webkit-border-top-left-radius: 12px;
border-top-left-radius: 12px;
-moz-border-radius-topright: 12px;
-webkit-border-top-right-radius: 12px;
border-top-right-radius: 12px;
top: 0;
left: 12px;
width: 24px;
height: 12px;
}
<span class="heartbeat">Loading...</span>
To understand the principle...
Using variables in CSS
is not possible at the moment and is unlikely to be possible anytime soon.
This is only available using CSS pre-processors, such as less or sass.
jsfiddle and codepen allow you to use scss
(sass) in the CSS
panel and correctly output the processed CSS
when rendering.
sass.js is a library that allows you to use .sass
files in <link>
tags and processes them into valid CSS
at load time.
It is likely that major browsers will soon be capable of processing .scss
, .sass
or .less
files natively and it is already possible by using browser extensions.
This, however, does not mean CSS
will ever support variables.
来源:https://stackoverflow.com/questions/42164133/css-animated-icon-resize