CSS property value from class name

前端 未结 5 1968
醉梦人生
醉梦人生 2020-11-27 06:55

It is possible to pass parameters for CSS in class name? For example:

.mrg-t-X {
   margin-top: Xpx;
}
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 07:22

    It isn't possible to directly pass parameters using just CSS but you're not the first person to ask - check out this question which looks at CSS and JavaScript options and also this might be helpful regarding attribute selection.

    This will only help if you are looking at a few variables of margin-top but I don't know what context you're using this in. Depending on what you're using it for there might be better ways.

    The simplest way would probably be just to add the style inline to your span but I try to stay away from inline CSS!

提交回复
热议问题