Is it possible to do mathematics inside CSS?

前端 未结 5 1066
孤独总比滥情好
孤独总比滥情好 2020-12-01 01:36

I have jquery accorion id #accordion and some of the content inside header class name .simpleColor. Now I want to give a calculated margin to .simp

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 02:18

    jQuery('.simpleClass').css('margin-left', (jQuery('#accordian').width() / 2) - (jQuery('.simpleColor').width() / 2) + 'px');
    

    Should do what you are wanting. But you need to do something like this in javascript, you can't do it in pure CSS unless the widths for #accordian and .simpleColor are known in advance (and thus calculated in advance).

提交回复
热议问题