我可以通过编程方式确定一系列CSS类的属性值吗?

编程入门 行业动态 更新时间:2024-10-28 08:26:03
本文介绍了我可以通过编程方式确定一系列CSS类的属性值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要帮助了解一个更简单的写法。

I need help understanding an easier way to write this.

我有一个数字在1-100之间的类。例如:

I have classes that have a number between 1-100 at the end of it. So for example:

.select1 { padding: 1em; } .select2 { padding: 2em; } .select3 { padding: 3em; }

等。

我想要匹配的数字与我想添加的数量,但不知道如何去在CSS中。

I want to match the number with the amount I want to add, but have no idea how to go about it in CSS. Instead of actually writing them out is there a more object oriented way of doing this in CSS?

推荐答案

你可以使用这种方法使用CSS扩展语言(如 SASS 或 LESS ,带有变量。

You could use a CSS extension language like SASS or LESS, with variables.

例如,使用SASS可以做一个for循环:

For example, with SASS you could do a for loop:

$class-slug: select !default @for $i from 1 through 100 .#{$class-slug}-#{$i} padding: $i + 0em

're寻找。

这不是一个纯CSS解决方案,但它打败每个人手。否则你也可以用Javascript做,但这不是理想。

It's not a pure CSS solution, but it beats doing each one by hand. Otherwise you could also do this with Javascript, but that's not ideal.

更多推荐

我可以通过编程方式确定一系列CSS类的属性值吗?

本文发布于:2023-08-04 06:49:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1294016.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以通过   属性   方式   系列   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!