javascript 在javascript中更改顶部填充
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9695468/
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
changing top padding in javascript
提问by xonegirlz
Here's how I set my top padding in my css:
这是我在 css 中设置顶部填充的方法:
body {
font-size: {{ font_size }}px;
margin: 0;
padding: 100px 0 20px 0;
width:100% !important;
}
How do I change the top padding, which is 100px on the example above using the simplest javascript function without using jQuery?
如何在不使用 jQuery 的情况下使用最简单的 javascript 函数更改上面示例中的 100px 顶部填充?
回答by Kristian
document.body.style.paddingTop = '10px'
回答by adedoy
JavaScript syntax: object.style.paddingTop="2cm"
JavaScript 语法: object.style.paddingTop="2cm"
see link: http://www.w3schools.com/cssref/pr_padding-top.asp
见链接:http: //www.w3schools.com/cssref/pr_padding-top.asp
so it should be:
所以应该是:
<!-- note that this chunk of code should be after the body tag to work -->
<script type="text/javascript">
document.body.style.paddingTop = "100px";
</script>