[英]Dynamically calculate padding-left
Here's a sample division: 这是一个示例部门:
<div style="padding:0 0 0 30px; background:url(http://www.google.com/help/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. 我想知道如何动态地计算padding-left:30px,以便我选择的padding-left值的任何图标根据图像宽度而变化。
Any help is appreciated! 任何帮助表示赞赏!
I would use jQuery : 我会使用jQuery :
$('div#id').css('padding-left');
You would need to have a way to select the DIV, hence my artificial #id
. 您将需要选择DIV的方法,因此是我的人工#id
。
Examples: http://jsfiddle.net/userdude/LvPH6/1/ 示例: http : //jsfiddle.net/userdude/LvPH6/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.