CoderTools Web site

CSS margin-bottom - Changing the bottom Margin of an HTML Element

Description



This command is used to change the size of the bottom margin of an html element.

default value is 0.
    margin-bottom: length;
    or
    margin-bottom: percentage;
    or
    margin-bottom: auto;
    or
    margin-bottom: inherit;
See also: margin, margin-left, margin-right, margin-top

Examples for margin-bottom

Example 1:

Simple example using a div (block level element) to show large 50px bottom margin. We add a border to make it easy to see the margin. Note that the margin is the distance between the border and the outer edge of the element (see the box model). So the border is not affected by the margin.

test text test text test text test text
    <style>
       #test {  margin-bottom: 50px; border:1px solid black; }
        #outer { border:1px solid black; }
    </style>
    
    <div id="outer">
        <div id="test">test text test text test text test text</div>
    </div>

Example 2:

test text test text test text test text

Same example but this time with a span (an inline element). Two things to note, 1) span is an inline element therefore the margin overlaps the surrounding elements (in internet explorer anyway! In firefox the margin-bottom is ignored for inline elements). And 2) inline elements do not collapse to the width of the enclosing element, the default size is to closely wrap the containing text and elements.

    <style>
        #test2 {  margin-bottom: 50px; border:1px solid black; }
        #outer { border:1px solid black; }
    </style>
    
    <span id="outer">
        <span id="test2">test text test text test text test text</span>
    </span>

Example 3:

This time using a div with a negative -25px value. This is a little weird - what happens is the element below the div can now appear 25 pixels into the div.

test text test text test text test text
    <style>
        #test3 {  margin-bottom: -25px; border:1px solid black; }
        #outer { border:1px solid black; }
    </style>
    
    <div id="outer">
        <div id="test3">test text test text test text test text</div>
    </div>

Values for margin-bottom


Name Values Description
margin-bottom length
%
auto
Specifies the size of the bottom margin.


TotalEdit Now Completely Free

CoderTools TotalEdit - The Free Text Editor

A powerful editor and notepad replacement TotalEdit makes it easier to complete your file editing and software development tasks. TotalEdit is FREE for commercial and non-commercial purposes (its freeware).

10/30/2014 3:24:23 PM
Terms Of Use | Privacy Statement | Copyright 2006-2010 © Independence Software LLP