box-align

  • Revision slug: CSS/box-align
  • Revision title: box-align
  • Revision id: 333449
  • Created:
  • Creator: sawrubh
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

{{ warning("This is a property of the original CSS Flexible Box Layout Module standard which is being replaced by a new standard.") }}

See Flexbox for more information.

 

Summary

The CSS box-align property specifies how an element aligns its contents across (perpendicular to) the direction of its layout. The effect of this is only visible if there is extra space in the box. See Flexbox for more about the properties of flexbox elements.

The direction of layout depends on the element's orientation: horizontal or vertical.

  • {{ Xref_cssinitial() }}: {{ Cssxref("stretch") }}
  • Applies to: elements with a CSS {{ Cssxref("display") }} value of {{ Cssxref("box") }} or {{ Cssxref("inline-box") }}
  • {{ Xref_cssinherited() }}: no
  • Percentages: n/a
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

box-align:         start | center | end | baseline | stretch     /* As specified */
-moz-box-align:    start | center | end | baseline | stretch     /* Mozilla */
-webkit-box-align: start | center | end | baseline | stretch     /* WebKit */

Values

start
The box aligns contents at the start, leaving any extra space at the end.
center
The box aligns contents in the center, dividing any extra space equally between the start and the end.
end
The box aligns contents at the end, leaving any extra space at the start.
baseline
The box aligns the baselines of the contents (lining up the text). This only applies if the box's orientation is horizontal.
stretch
The box stretches the contents so that there is no extra space in the box.

Examples

<!DOCTYPE html>
<html>
  <head>
    <title>CSS box-align example</title>
    <style>
      div.example {
        display: box;                   /* As specified */
        display: -moz-box;              /* Mozilla */
        display: -webkit-box;           /* WebKit */
        
        /* Make this box taller than the children, 
           so there is room for the box-pack */
        height: 400px;           
        
        /* Make this box wider than the children
           so there is room for the box-align */
        width: 300px;

        /* Children should be oriented vertically */
        box-orient: vertical;           /* As specified */
        -moz-box-orient: vertical;      /* Mozilla */
        -webkit-box-orient: vertical;   /* WebKit */

        /* Align children to the horizontal center of this box */
        box-align: center;              /* As specified */
        -moz-box-align: center;         /* Mozilla */
        -webkit-box-align: center;      /* WebKit */
        
        /* Pack children to the bottom of this box */
        box-pack: end;                  /* As specified */
        -moz-box-pack: end;             /* Mozilla */
        -webkit-box-pack: end;          /* WebKit */
      }
      div.example > p {            
        /* Make children narrower than their parent, 
           so there is room for the box-align */ 
        width: 200px;
      }
    </style>
  </head>
  <body>
    <div class="example">
      <p>I will be second from the bottom of div.example, centered horizontally.</p>
      <p>I will be on the bottom of div.example, centered horizontally.</p>
    </div>
  </body>
</html>

Notes

The edge of the box designated the start for alignment purposes depends on the box's orientation:

Horizontal top
Vertical left

The edge opposite to the start is designated the end.

If the alignment is set using the element's align attribute, then the style is ignored.

Specifications

Flexible Box Layout Module (W3C Working Draft)

{{ note("The current state of this specification does not reflect Mozilla's or WebKit's implementation.") }}

Old Flexible Box Layout Module

{{ note("WebKit and Mozilla's implementations reflect this version of the specification") }}

             
             

See also

{{ cssxref("box-orient") }}, {{ cssxref("box-direction") }}, {{ cssxref("box-pack") }}

{{ languages( { "fr": "fr/CSS/-moz-box-align", "pl": "pl/CSS/-moz-box-align" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<p>{{ warning("This is a property of the&nbsp;original CSS Flexible Box Layout Module standard which is being replaced by a new standard.") }}</p>
<p>See <a href="/en/CSS/Flexbox" title="/en/CSS/Flexible_boxes">Flexbox</a>&nbsp;for more information.</p>
<p>&nbsp;</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>The CSS <code>box-align</code> property specifies how an element aligns its contents across (perpendicular to) the direction of its layout. The effect of this is only visible if there is extra space in the box.&nbsp;See&nbsp;<a href="/en/CSS/Flexbox" title="/en/CSS/Flexible_boxes">Flexbox</a>&nbsp;for more about the properties of flexbox elements.</p>
<p>The direction of layout depends on the element's orientation: horizontal or vertical.</p>
<ul>
  <li>{{ Xref_cssinitial() }}: {{ Cssxref("stretch") }}</li>
  <li>Applies to: elements with a CSS {{ Cssxref("display") }} value of {{ Cssxref("box") }} or {{ Cssxref("inline-box") }}</li>
  <li>{{ Xref_cssinherited() }}: no</li>
  <li>Percentages: n/a</li>
  <li>Media: {{ Xref_cssvisual() }}</li>
  <li>{{ Xref_csscomputed() }}: as specified</li>
</ul>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">
box-align:         start | center | end | baseline | stretch     /* As specified */
-moz-box-align:    start | center | end | baseline | stretch     /* Mozilla */
-webkit-box-align: start | center | end | baseline | stretch     /* WebKit */
</pre>
<h3 id="Values" name="Values">Values</h3>
<dl>
  <dt>
    <code>start</code></dt>
  <dd>
    The box aligns contents at the start, leaving any extra space at the end.</dd>
  <dt>
    <code>center</code></dt>
  <dd>
    The box aligns contents in the center, dividing any extra space equally between the start and the end.</dd>
  <dt>
    <code>end</code></dt>
  <dd>
    The box aligns contents at the end, leaving any extra space at the start.</dd>
  <dt>
    <code>baseline</code></dt>
  <dd>
    The box aligns the baselines of the contents (lining up the text). This only applies if the box's orientation is horizontal.</dd>
  <dt>
    <code>stretch</code></dt>
  <dd>
    The box stretches the contents so that there is no extra space in the box.</dd>
</dl>
<h3 id="Examples" name="Examples">Examples</h3>
<pre class="brush: html">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;CSS box-align example&lt;/title&gt;
    &lt;style&gt;
      div.example {
        display: box;                   /* As specified */
        display: -moz-box;              /* Mozilla */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;display: -webkit-box;           /* WebKit */
        
        /* Make this box taller than the children, 
           so there is room for the box-pack */
        height: 400px;           
        
        /* Make this box wider than the children
           so there is room for the box-align */
        width: 300px;

        /* Children should be oriented vertically */
        box-orient: vertical;           /* As specified */
        -moz-box-orient: vertical;      /* Mozilla */
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-webkit-box-orient: vertical;   /* WebKit */

        /* Align children to the horizontal center of this box */
        box-align: center;              /* As specified */
        -moz-box-align: center;         /* Mozilla */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;-webkit-box-align: center;      /* WebKit */
        
        /* Pack children to the bottom of this box */
        box-pack: end;                  /* As specified */
        -moz-box-pack: end;             /* Mozilla */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;-webkit-box-pack: end;          /* WebKit */
      }
      div.example &gt; p {            
        /* Make children narrower than their parent, 
           so there is room for the box-align */ 
        width: 200px;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class="example"&gt;
      &lt;p&gt;I will be second from the bottom of div.example, centered horizontally.&lt;/p&gt;
      &lt;p&gt;I will be on the bottom of div.example, centered horizontally.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<h3 id="Notes" name="Notes">Notes</h3>
<p>The edge of the box designated the <em>start</em> for alignment purposes depends on the box's orientation:</p>
<table cellspacing="8" class="standard-table" style="text-align:center;">
  <tbody>
    <tr>
      <th style="text-align:right;"><strong>Horizontal</strong></th>
      <td>top</td>
    </tr>
    <tr>
      <th style="text-align:right;"><strong>Vertical</strong></th>
      <td>left</td>
    </tr>
  </tbody>
</table>
<p>The edge opposite to the start is designated the <em>end</em>.</p>
<p>If the alignment is set using the element's <code>align</code> attribute, then the style is ignored.</p>
<h3 id="Specifications" name="Specifications">Specifications</h3>
<p><a class="external" href="http://www.w3.org/TR/css3-flexbox/">Flexible Box Layout Module (W3C Working Draft)</a></p>
<p>{{ note("The current state of this specification does not reflect Mozilla's or WebKit's implementation.") }}</p>
<p><a class="external" href="http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/">Old Flexible Box Layout Module</a></p>
<p>{{ note("WebKit and Mozilla's implementations reflect this version of the specification") }}</p>
<table class="compat-table" height="57" width="78">
  <tbody>
    <tr>
      <th>&nbsp;</th>
      <th>&nbsp;</th>
      <th>&nbsp;</th>
      <th>&nbsp;</th>
      <th>&nbsp;</th>
      <th>&nbsp;</th>
      <th>&nbsp;</th>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="See_Also" name="See_Also">See also</h2>
<p>{{ cssxref("box-orient") }}, {{ cssxref("box-direction") }}, {{ cssxref("box-pack") }}</p>
<p>{{ languages( { "fr": "fr/CSS/-moz-box-align", "pl": "pl/CSS/-moz-box-align" } ) }}</p>
Revert to this revision