You are here: Reference > JavaScript > client-side > style handling > properties > marginBottom

marginBottom style property

Browser support:
Specifies or returns the bottom margin of the object.
With the marginBottom property you can specify the distance between the element's bottommost position and the bottom borderBottom.

Syntax:

object.marginBottom;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: margin-bottom

Possible values:

The type of this property is string.
 One of the following values: 
auto
Default. The sizes of the 'auto' margins are equal.
height in length
The height of the bottom margin in length units. For the supported length units, see the length page.
height in percentage
The height is the specified percentage of the width of the parent element.
inherit
Takes the value of this property from the computed style of the parent element.
Default: 0.

Example HTML code 1:

This example illustrates the use of the margin-bottom, border and padding properties:
<head>
    <style>
        .outer {
            border: 1px solid #ffffff;
            background-color: #ffb08a;
        }
        .middle {
            margin-bottom: 20px;
            padding: 20px;
            border: 10px solid #000000;
            background-color: #ceb379;
        }
        .inner {
            height: 10px;
            border: 1px solid #ffffff;
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <table cellpadding="0px" cellspacing="10px">
        <tr>
            <td style="background-color: #ffb08a;">&nbsp;</td>
            <td>margin</td>
            <td style="background-color: #000000;">&nbsp;</td>
            <td>border</td>
            <td style="background-color: #ceb379;">&nbsp;</td>
            <td>padding</td>
        </tr>
    </table>
    
    <div class="outer">
        <div class="middle">
            <div class="inner"></div>
        </div>
    </div>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the marginBottom property in JavaScript:
<head>
    <style>
        .outer {
            border: 1px solid #ffffff;
            background-color: #ffb08a;
        }
        .middle {
            margin-bottom: 20px;
            padding: 20px;
            border: 10px solid #000000;
            background-color: #ceb379;
        }
        .inner {
            height: 10px;
            border: 1px solid #ffffff;
            background-color: #ffffff;
        }
    </style>
    <script type="text/javascript">
        function ChangeMarginBottom () {
            var middleDiv = document.getElementById ("middleDiv");
            var marginInput = document.getElementById ("marginInput");

            middleDiv.style.marginBottom = marginInput.value + "px";
        }
    </script>
</head>
<body>
    <table cellpadding="0px" cellspacing="10px">
        <tr>
            <td style="background-color: #ffb08a;">&nbsp;</td>
            <td>margin</td>
            <td style="background-color: #000000;">&nbsp;</td>
            <td>border</td>
            <td style="background-color: #ceb379;">&nbsp;</td>
            <td>padding</td>
        </tr>
    </table>
    <div class="outer">
        <div id="middleDiv" class="middle">
            <div class="inner"></div>
        </div>
    </div>
    <br />
    marginBottom: 
    <input id="marginInput" type="text" value="10" size="2" /> 
    <button onclick="ChangeMarginBottom ();">Change</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content