Dynamically calculate padding-left
Here's a sample division:
<div style="padding:0 0 0 30px; background:url(http://www.google.com/hel开发者_Go百科p/hc/images/sidewiki_157505_comment_bubble.gif) left center no-repeat;">some text</div>
I wonder how I can calculate the padding-left:30px dynamically so that any icon I choose the padding-left value changes according to the image width.
Any help is appreciated!
I would use jQuery:
$('div#id').css('padding-left');
You would need to have a way to select the DIV, hence my artificial #id
.
Examples: http://jsfiddle.net/userdude/LvPH6/1/
精彩评论