CSS property value from class name
No, it is not. The closest thing to this is a attr()
function , but this only works on a property content
:
figure::before {
content: attr(data-before) ', ';
}
figure::after {
content: attr(data-after) '!';
}
<figure data-before="Hello" data-after="world"></figure>
Perhaps one day this will be expanded so that we can use it elsewhere, but this is not yet possible.
Currently, since I'm sure you know if you want to use the class .mrg-t-X
, you will need to define separate style rules for each X
you want to allow:
.mrg-t-1 { ... }
.mrg-t-2 { ... }
.mrg-t-3 { ... }
...
source to share
It is not possible to pass parameters directly using CSS alone, but you are not the first person interested - check out this question that looks at CSS and JavaScript options, and this one might also be useful when choosing attributes.
It helps if you look at multiple variables margin-top
, but I don't know what context you are using this in. Depending on what you are using for this, there may be better ways.
The simplest way would probably be to just add inline style to your span <span style="margin-top:10px">
, but I try to stay away from inline CSS!
source to share