문제

Ok. What I would like to do is to use jQuery to go through all <span> tags with a certain class (.link) and to set their padding-right css value to 20% of current width of the span.

I do not have any code to show because I am not good with jQuery and the rest is pretty much self-explanatory.

Any help would be much appreciated. Thanks :)

도움이 되었습니까?

해결책

You can use the css() method with a callback function that returns the width of the currently iterated element x 0.2

$('span.link').css('padding-right', function() {
    return $(this).width() * 0.2;
});

In newer browsers you could do this with CSS as well

span.link { padding-right: calc(20%); }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top