Javascript examples for CSS Style Property:marginRight
The marginRight property sets or gets the right margin of an element.
Value | Description |
---|---|
% | right margin in percentage of the width of the parent element |
length | right margin in length units |
auto | The browser sets the right margin |
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 right margin of an element |
CSS Version | CSS1 |
Set the right margin of a <div> element:
<!DOCTYPE html> <html> <head> <style> #myDiv {//from w w w . j a v a 2 s .c o m border: 1px solid #FF0000; } </style> </head> <body> <div id="myDiv" style="margin-right:5cm;">This is a div.</div> <br> <button type="button" onclick="myFunction()">test</button> <script> function myFunction() { document.getElementById("myDiv").style.marginRight = '10px'; } </script> </body> </html>