blob: 8d80a3124eb99fe4203f019427cc2ecd8d51ebb0 [file] [log] [blame]
<h2 id="introduction">Introduction</h2>
<p>The Material Design Lite (MDL) <strong>card</strong> component is a user interface element representing a virtual piece of paper that contains related data &mdash; such as a photo, some text, and a link &mdash; that are all about a single subject.</p>
<p>Cards are a convenient means of coherently displaying related content that is composed of different types of objects. They are also well-suited for presenting similar objects whose size or supported actions can vary considerably, like photos with captions of variable length. Cards have a constant width and a variable height, depending on their content.</p>
<p>Cards are a fairly new feature in user interfaces, and allow users an access point to more complex and detailed information. Their design and use is an important factor in the overall user experience. See the card component&#39;s <a href="http://www.google.com/design/spec/components/cards.html">Material Design specifications page</a> for details.</p>
<h3 id="to-include-an-mdl-card-component-">To include an MDL <strong>card</strong> component:</h3>
<p>&nbsp;1. Code a <code>&lt;div&gt;</code> element; this is the &quot;outer&quot; container, intended to hold all of the card&#39;s content.</p>
<pre><code class="lang-html">&lt;div&gt;
&lt;/div&gt;
</code></pre>
<p>&nbsp;2. Inside the div, code one or more &quot;inner&quot; divs, one for each desired content block. A card containing a title, an image, some text, and an action bar would contain four &quot;inner&quot; divs, all siblings.</p>
<pre><code class="lang-html">&lt;div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>&nbsp;3. Add one or more MDL classes, separated by spaces, to the &quot;outer&quot; div and the &quot;inner&quot; divs (depending on their intended use) using the <code>class</code> attribute.</p>
<pre><code class="lang-html">&lt;div class=&quot;mdl-card&quot;&gt;
&lt;div class=&quot;mdl-card__title&quot;&gt;
...
&lt;/div&gt;
&lt;div class=&quot;mdl-card__media&quot;&gt;
...
&lt;/div&gt;
&lt;div class=&quot;mdl-card__supporting-text&quot;&gt;
...
&lt;/div&gt;
&lt;div class=&quot;mdl-card__actions&quot;&gt;
...
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>&nbsp;4. Add content to each &quot;inner&quot; div, again depending on its intended use, using standard HTML elements and, optionally, additional MDL classes.</p>
<pre><code class="lang-html">&lt;div class=&quot;mdl-card&quot;&gt;
&lt;div class=&quot;mdl-card__title&quot;&gt;
&lt;h2 class=&quot;mdl-card__title-text&quot;&gt;title Text Goes Here&lt;/h2&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-card__media&quot;&gt;
&lt;img src=&quot;photo.jpg&quot; width=&quot;220&quot; height=&quot;140&quot; border=&quot;0&quot; alt=&quot;&quot; style=&quot;padding:20px;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-card__supporting-text&quot;&gt;
This text might describe the photo and provide further information, such as where and
when it was taken.
&lt;/div&gt;
&lt;div class=&quot;mdl-card__actions&quot;&gt;
&lt;a href=&quot;(URL or function)&quot;&gt;Related Action&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>The card component is ready for use.</p>
<h4 id="examples">Examples</h4>
<p>A card (no shadow) with a title, image, text, and action.</p>
<pre><code class="lang-html">&lt;div class=&quot;mdl-card&quot;&gt;
&lt;div class=&quot;mdl-card__title&quot;&gt;
&lt;h2 class=&quot;mdl-card__title-text&quot;&gt;Auckland Sky Tower&lt;br&gt;Auckland, New Zealand&lt;/h2&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-card__media&quot;&gt;
&lt;img src=&quot;skytower.jpg&quot; width=&quot;173&quot; height=&quot;157&quot; border=&quot;0&quot; alt=&quot;&quot;
style=&quot;padding:10px;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-card__supporting-text&quot;&gt;
The Sky Tower is an observation and telecommunications tower located in Auckland,
New Zealand. It is 328 metres (1,076 ft) tall, making it the tallest man-made structure
in the Southern Hemisphere.
&lt;/div&gt;
&lt;div class=&quot;mdl-card__actions&quot;&gt;
&lt;a href=&quot;http://en.wikipedia.org/wiki/Sky_Tower_%28Auckland%29&quot;&gt;Wikipedia entry&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Card (level-3 shadow) with an image, caption, and text:</p>
<pre><code class="lang-html">&lt;div class=&quot;mdl-card mdl-shadow--4dp&quot;&gt;
&lt;div class=&quot;mdl-card__media&quot;&gt;&lt;img src=&quot;skytower.jpg&quot; width=&quot;173&quot; height=&quot;157&quot; border=&quot;0&quot;
alt=&quot;&quot; style=&quot;padding:10px;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-card__supporting-text&quot;&gt;
Auckland Sky Tower, taken March 24th, 2014
&lt;/div&gt;
&lt;div class=&quot;mdl-card__supporting-text&quot;&gt;
The Sky Tower is an observation and telecommunications tower located in Auckland,
New Zealand. It is 328 metres (1,076 ft) tall, making it the tallest man-made structure
in the Southern Hemisphere.
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<h2 id="configuration-options">Configuration options</h2>
<p>The MDL CSS classes apply various predefined visual and behavioral enhancements to the card. The table below lists the available classes and their effects.</p>
<table>
<thead>
<tr>
<th>MDL class</th>
<th>Effect</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>mdl-card</code></td>
<td>Defines div element as an MDL card container</td>
<td>Required on &quot;outer&quot; div</td>
</tr>
<tr>
<td><code>mdl-card--border</code></td>
<td>Adds a border to the card section that it&#39;s applied to</td>
<td>Used on the &quot;inner&quot; divs</td>
</tr>
<tr>
<td><code>mdl-shadow--2dp through mdl-shadow--16dp</code></td>
<td>Assigns variable shadow depths (2, 3, 4, 6, 8, or 16) to card</td>
<td>Optional, goes on &quot;outer&quot; div; if omitted, no shadow is present</td>
</tr>
<tr>
<td><code>mdl-card__title</code></td>
<td>Defines div as a card title container</td>
<td>Required on &quot;inner&quot; title div</td>
</tr>
<tr>
<td><code>mdl-card__title-text</code></td>
<td>Assigns appropriate text characteristics to card title</td>
<td>Required on head tag (H1 - H6) inside title div</td>
</tr>
<tr>
<td><code>mdl-card__subtitle-text</code></td>
<td>Assigns text characteristics to a card subtitle</td>
<td>Optional. Should be a child of the title element.</td>
</tr>
<tr>
<td><code>mdl-card__media</code></td>
<td>Defines div as a card media container</td>
<td>Required on &quot;inner&quot; media div</td>
</tr>
<tr>
<td><code>mdl-card__supporting-text</code></td>
<td>Defines div as a card body text container and assigns appropriate text characteristics to body text</td>
<td>Required on &quot;inner&quot; body text div; text goes directly inside the div with no intervening containers</td>
</tr>
<tr>
<td><code>mdl-card__actions</code></td>
<td>Defines div as a card actions container and assigns appropriate text characteristics to actions text</td>
<td>Required on &quot;inner&quot; actions div; content goes directly inside the div with no intervening containers</td>
</tr>
<tr>
<td><code>mdl-card__menu</code></td>
<td>Defines element as top right menu button</td>
<td>Optional. Should be a child of the <code>mdl-card</code> element.</td>
</tr>
</tbody>
</table>