简体   繁体   English

我可以在CSS中编写自己的伪函数吗

[英]can I write my own pseudo function in CSS

Consider this: 考虑一下:

.voffset1 { margin-top: 1px; }
.voffset2 { margin-top: 2px; }
.voffset3 { margin-top: 3px; }
......
.voffset100 { margin-top: 100px; }

Is it possible to turn this into a function in CSS or CSS3 是否可以将其转换为CSS或CSS3中的函数
so I don't have to manually have 100 css classes, but 所以我不必手动拥有100个CSS类,但是
just have 1 css 'function' for it? 仅具有1个CSS“功能”吗?

like below: 如下所示:

.voffset:(n) {margin-top : (n)px;}

if not, can we do better than writing 100 lines? 如果没有,我们能写出100行以上吗?

I prefer not using scss or any variants. 我更喜欢不使用scss或任何变体。

Sure. 当然。

<div style="margin-top:1px">

When your CSS is so obviously redundant, just use inline styles. 当CSS如此明显地多余时,只需使用内联样式。

Or redesign your code to actually use classes properly. 或重新设计代码以实际正确使用类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM