简体   繁体   English

你如何在jQuery中更改元素的填充?

[英]How do you change the padding of an element in jQuery?

I am using the following code 我使用以下代码

$("#numbers a").css({
"color":"white",
"text-decoration":"none",
"padding:":"5px"
});

The color and text-decoration change just fine, but the padding is not added to the element. 颜色和文本修饰都很好,但填充不会添加到元素中。 How should I fix this? 我该怎么解决这个问题?

You have a stray colon in your padding property which is causing it to not be recognized: 你的padding属性中有一个迷路冒号,导致它无法被识别:

"padding:":"5px"

Remove it and it should work: 删除它,它应该工作:

"padding":"5px"

In the : is just a typo in to your post, you might be confused with padding and inline elements. 在:只是你的帖子中的一个错字,你可能会与填充和内联元素混淆。

Your selector "#numbers a" hints you are referencing an anchor tag. 您的选择器"#numbers a"提示您引用锚标记。 An anchor tag is an inline element and inline elements do not have padding on all sides. 锚标记是内联元素,内联元素的所有边都没有填充。 Nice article on padding|widths with inline elements 有关内联元素的填充|宽度的好文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM