Is it possible to do mathematics inside CSS?

前端 未结 5 1068
孤独总比滥情好
孤独总比滥情好 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:13

    I believe the CSS should be pure style definition. I dont like to mix some calculations with that. I would do that in my javascript

    var accWidth=parseInt($("#accordion").css("width").replace("px",""));
    var simpWidth=parseInt($(".simpleColor").css("width").replace("px",""));
    var marginLeft=((accWidth/2)-(simpWidth/2));       
    $(".simpleClass").css("margin-left",marginLeft);
    

    Working sample http://jsfiddle.net/mzTRw/19/

提交回复
热议问题