How to pass a parameter to a CSS class using LESS?

2019-03-01 06:48发布

问题:

Not sure if this is possible using LESS, but I saw .rotate(@degrees) {...} (is that only work in LESS)

I want to be able to write one CSS class and pass the number as a parameter from the HTML - for example: <div class="opacity(20)">

Here is just an example of a repeated CSS class that I use (but even passing an integer will be great):

.opacity-10 {
  opacity: 0.1;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=10)"; // IE 8
  filter: alpha(opacity=10); // IE 5-7
  -moz-opacity: 0.1; // Netscape
  -khtml-opacity: 0.1; // Safari 1.x
}
.opacity-20 {
  opacity: 0.2;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)"; // IE 8
  filter: alpha(opacity=20); // IE 5-7
  -moz-opacity: 0.2; // Netscape
  -khtml-opacity: 0.2; // Safari 1.x
}

// ...
标签: css less