最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding margin with Jquery - Stack Overflow

programmeradmin0浏览0评论

I am trying to center tags within a div but depending on what page you are on it can depend on how many tags there will be as it's for an image gallery. So i am trying to do it with Jquery.

Basically what i want to say is:

For every tag add 5% to the margin.

Can someone point me in the right direction to do so. I was thinking of using the .size() to calculate the amount of tags but not sure where to go then.

Thanks.

I am trying to center tags within a div but depending on what page you are on it can depend on how many tags there will be as it's for an image gallery. So i am trying to do it with Jquery.

Basically what i want to say is:

For every tag add 5% to the margin.

Can someone point me in the right direction to do so. I was thinking of using the .size() to calculate the amount of tags but not sure where to go then.

Thanks.

Share Improve this question asked Mar 19, 2012 at 11:39 JDaviesJDavies 2,7707 gold badges36 silver badges55 bronze badges 3
  • 1 provide some code sample – Amit Soni Commented Mar 19, 2012 at 11:41
  • Do you mean you want the margin to be 5% per item in the div (so 3 items == 15%), or just 5% margin on each item? – Matt Sach Commented Mar 19, 2012 at 11:45
  • Ill post an answer but im not sure if it is what you need? I think you mean: For x amount of tags add 5% margin to each? Or x amount of tags * 5% = margin on a certain element? – Undefined Commented Mar 19, 2012 at 11:45
Add a ment  | 

1 Answer 1

Reset to default 7

Use the * selector

$("*").css("margin","5%");

However, for the safety purposes, you have to limit the use of such wildcard selector. There are lots of other ways you can select mass elements.

  1. Class Selecotors: $(".myclass')
  2. Tag Selecotors: $("div")
  3. Atrribute: $("input[type="text"]')
发布评论

评论列表(0)

  1. 暂无评论