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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4534295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 12:48:38  来源:igfitidea点击:

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

javascriptjquerycss

提问by Zak

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?

颜色和文本装饰改变得很好,但填充没有添加到元素中。我应该如何解决这个问题?

回答by BoltClock

You have a stray colon in your paddingproperty which is causing it to not be recognized:

您的padding财产中有一个流浪冒号,导致它无法被识别:

"padding:":"5px"

Remove it and it should work:

删除它,它应该可以工作:

"padding":"5px"

回答by epascarello

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. 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

您的选择器"#numbers a"提示您正在引用锚标记。锚标记是内联元素,内联元素的所有边都没有填充。关于带内嵌元素的填充|宽度的好文章