MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla

Revision 409869 of right

  • Revision slug: Web/CSS/right
  • Revision title: right
  • Revision id: 409869
  • Created:
  • Creator: Zenorbi
  • Is current revision? No
  • Comment The document differed from the specification in the case of the right is relative the the element's containing block, and the percentage is the element's containing block, while the specs say that it is relative to the first non-static positioned parent.

Revision Content

{{CSSRef}}

Summary

The right CSS property specifies part of the position of positioned elements.

For absolutely positioned elements (those with {{Cssxref("position")}}: absolute or position: fixed), it specifies the distance between the right margin edge of the element and the right edge of its first non-static positioned parent.

The right property has no effect on non-positioned elements.

When both the right CSS property and the {{cssxref("left")}} CSS property are defined, the position of the element is overspecified. In that case, the {{cssxref("left")}} value has precedence when the container is left-to-right (that is that the right computed value is set to -left), and the right value has precedence when the container is right-to-left (that is that the {{cssxref("left")}} computed value is set to -right).

{{cssbox("right")}}

Syntax

Formal syntax: {{csssyntax("right")}}
right: 3px         /* <length> values */
right: 2.4em

right: 10%         /* <percentages> of the width of the first non-static positioned parent */

right: auto

right: inherit

Values

<length>
Is a negative, null or positive {{xref_csslength}} that represents:
  • for absolutely positioned elements, the distance to the right edge of the first non-static positioned parent;
  • for relatively positioned elements, the offset that the element is moved right from its position in the normal flow if it wasn't positioned.
<percentage>
Is a {{xref_csspercentage}} of the first non-static positioned parent's width, used as described in the summary.
auto
Is a keyword that represents:
  • for absolutely positioned elements, the position the element based on the {{Cssxref("left")}} property and treat width: auto as a width based on the content.
  • for relatively positioned elements, the right offset the element from its original position based on the {{Cssxref("left")}} property, or if left is also auto, do not offset it at all.
inherit
Is a keyword indicating that the value is the same than the computed value from its parent element (which may not be its containing block). This computed value is then handled like it was a {{xref_csslength}}, {{xref_csspercentage}} or the auto keyword.

Examples

{{CSSLiveSample("css-positioning.html")}}

#example_3 {
  width: 600px;
  height: 400px;
  background-color: #FFC7E4;
  position: relative;
  top: 20px;
  left: 20px;
}

#example_4 {
  width:200px;
  height:200px;
  background-color: #FFD7C2;
  position:absolute;
  bottom:10px;
  right: 20px;
}

Specifications

Specification Status Comment
{{SpecName('CSS3 Transitions', '#animatable-css', 'right')}} {{Spec2('CSS3 Transitions')}} Defines right as animatable.
{{SpecName('CSS2.1', 'visuren.html#propdef-right', 'right')}} {{Spec2('CSS2.1')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1")}} 5.5 5.0 1.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 {{CompatGeckoMobile("1")}} 6.0 6.0 1.0

See also

  • {{CSS_Reference:Position}}

Revision Source

<div>
  {{CSSRef}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>right</code> <a href="/en-US/docs/CSS" title="CSS">CSS</a> property specifies part of the position of positioned elements.</p>
<p>For absolutely positioned elements (those with {{Cssxref("position")}}<code>:</code> <code>absolute</code> or <code>position:</code> <code>fixed</code>), it specifies the distance between the right margin edge of the element and the right edge of its first non-static positioned parent.</p>
<p>The <code>right</code> property has no effect on non-positioned elements.</p>
<p>When both the <code>right</code> CSS property and the {{cssxref("left")}} CSS property are defined, the position of the element is<em> overspecified</em>. In that case, the {{cssxref("left")}} value has precedence when the container is left-to-right (that is that the <code>right</code> computed value is set to <code>-left</code>), and the <code>right</code> value has precedence when the container is right-to-left (that is that the {{cssxref("left")}} computed value is set to <code>-right</code>).</p>
<p>{{cssbox("right")}}</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("right")}}
</pre>
<pre>
right: 3px         /* &lt;length&gt; values */
right: 2.4em

right: 10%         /* &lt;percentages&gt; of the width of the first non-static positioned parent */

right: auto

right: inherit
</pre>
<h3 id="Values" name="Values">Values</h3>
<dl>
  <dt>
    <code>&lt;length&gt;</code></dt>
  <dd>
    Is a negative, null or positive {{xref_csslength}} that represents:
    <ul>
      <li>for <em>absolutely positioned elements</em>, the distance to the right edge of the first non-static positioned parent;</li>
      <li>for <em>relatively positioned elements</em>, the offset that the element is moved right from its position in the normal flow if it wasn't positioned.</li>
    </ul>
  </dd>
  <dt>
    <code>&lt;percentage&gt;</code></dt>
  <dd>
    Is a {{xref_csspercentage}} of the first non-static positioned parent's width, used as described in the <a href="#Summary">summary</a>.</dd>
  <dt>
    <code>auto</code></dt>
  <dd>
    Is a keyword that represents:
    <ul>
      <li>for absolutely positioned elements, the position the element based on the {{Cssxref("left")}} property and treat <code>width: auto</code> as a width based on the content.</li>
      <li>for relatively positioned elements, the right offset the element from its original position based on the {{Cssxref("left")}} property, or if <code>left</code> is also <code>auto</code>, do not offset it at all.</li>
    </ul>
  </dd>
  <dt>
    <code>inherit</code></dt>
  <dd>
    Is a keyword indicating that the value is the same than the computed value from its parent element (which may not be its containing block). This computed value is then handled like it was a {{xref_csslength}}, {{xref_csspercentage}} or the <code>auto</code> keyword.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<p>{{CSSLiveSample("css-positioning.html")}}</p>
<pre class="brush: css; highlight:[16]">
#example_3 {
&nbsp;&nbsp;width: 600px;
&nbsp;&nbsp;height: 400px;
&nbsp;&nbsp;background-color: #FFC7E4;
&nbsp;&nbsp;position: relative;
&nbsp;&nbsp;top: 20px;
&nbsp;&nbsp;left: 20px;
}

#example_4 {
&nbsp;&nbsp;width:200px;
&nbsp;&nbsp;height:200px;
&nbsp;&nbsp;background-color: #FFD7C2;
&nbsp;&nbsp;position:absolute;
&nbsp;&nbsp;bottom:10px;
&nbsp;&nbsp;right: 20px;
}</pre>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'right')}}</td>
      <td>{{Spec2('CSS3 Transitions')}}</td>
      <td>Defines <code>right</code> as animatable.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS2.1', 'visuren.html#propdef-right', 'right')}}</td>
      <td>{{Spec2('CSS2.1')}}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<div>
  {{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{CompatGeckoDesktop("1")}}</td>
        <td>5.5</td>
        <td>5.0</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{CompatGeckoMobile("1")}}</td>
        <td>6.0</td>
        <td>6.0</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{CSS_Reference:Position}}</li>
</ul>
Revert to this revision