13

Here's how I set my top padding in my 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?

2 Answers 2

30
document.body.style.paddingTop = '10px'
Sign up to request clarification or add additional context in comments.

3 Comments

I don't want to use jQuery I want javascript
so is it document.getElementById("body").style.top = "20px";
Even without jQuery you can use document.body.
0

JavaScript syntax: object.style.paddingTop="2cm"

see link: 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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.