asp.net.ph

Skip Navigation Links

margin-right Attribute | marginRight Property

CSS Attributes Index   Box Attributes


Sets or retrieves the width of the right margin for the object.

Syntax


CSS { margin-right: [ length | percentage | 'auto' ] }
Script object.style.marginRight = [ length | percentage | 'auto' ]

Possible Values


length Floating-point number and a valid CSS length unit: either an absolute units designator ( cm, mm, in, pt, pc, or px ) or a relative units designator ( em or ex ).
percentage Value expressed as a percentage of the parent object’s height.
auto Value is set to be equal to the value of the opposite side.

The property is read/write with a default value of 0; this attribute is not inherited.

Remarks

Negative margins are supported except for top and bottom margins on inline objects.

The width property must be set on a SPAN object for the margin properties to render.

Possible length values specified in a relative measurement using the height of the element’s font ( em ) or the height of the letter "x" ( ex ) are supported as of Microsoft® Internet Explorer® 4.0 or later.

Example

The following examples demonstrate use of inline event handlers to dynamically set the right margin of an element. Both methods yield the same effect.

The sample below defines margin-right style attributes in an embedded stylesheet, and invokes calls to the stylesheet in response to mouse events.

<style type="text/css">
<!--
   .wideright { margin-right: 10mm }
-->
</style>
...
<img src="../shared/images/samp.jpg"
   onclick="this.className='wideright'"
   ondblclick="this.className=''">

 Show me 

The sample below uses inline event handlers to dynamically set an object’s right margin in response to mouse events.

<img src="../shared/images/samp03.jpg"
   onclick="this.style.marginRight='1cm'"
   ondblclick="this.style.marginRight=''">

 Show me 

See Also

paddingRight, CSS Length Units



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note