Javascript examples for CSS Style Property:padding
The padding property sets or gets the padding of an element.
This property can take from one to four values:
Value | Description |
---|---|
% | padding in percentage of the width of the parent element |
length | padding in length units |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
Item | Value |
---|---|
Default Value: | 0 |
Return Value: | A String, representing the padding of an element |
CSS Version | CSS1 |
Set the padding of a <div> element:
<!DOCTYPE html> <html> <head> <style> #myDiv {//from www.j ava2s .c o m border: 1px solid #FF0000; } </style> </head> <body> <div id="myDiv" style="padding-top:5cm;">This is a div.</div> <br> <button type="button" onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myDiv").style.padding = '10px 20px 30px 40px'; } </script> </body> </html>