[英]How to deduct 10px from dynamically calculated percentage margin?
I am adding some points to a div dynamically like 我正在动态地为div添加一些点
var space = 7.14286;
for (i = 0; i <13; i++) {
$('div').append('<span class="point"></span>');
}
$('.point').css('margin-left', (space+'%') );
while each point has : 而每个点都有:
.point{
display:inline-block;
width:20px;
height:20px
}
I need to deduct 10px
from each margin to locate the .point exactly at the center? 我需要从每个边距中扣除10px
,以便将.point准确定位在中心位置? How can I dynamically deduct this or use the center of div as margin border? 如何动态扣除这个或使用div的中心作为保证金边界?
您应该像这样使用CSS calc()
:
$('.point').css('margin-left', `calc(${space}% - 10px)`);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.