Cards
#
InstallationFor detailed instructions, view our install section in this documentation. Make sure all of the dependencies and polyfills are loaded to make the component cross-browser compatible.
#
CDN<script src="https://unpkg.com/@pearson-ux/card"></script>
#
NPMnpm i @pearson-ux/card --save
#
Demo<pearson-card> <div>Single Card</div></pearson-card>
#
StructureThe card layout can adjust automatically by using our grid system in CSS. All you need to do is wrap the cards in a <div class="gr-grid-container">
container.
#
Row Layout<div class="gr-grid-container ie-flex"> <pearson-card> <div>Card One</div> </pearson-card> <pearson-card> <div>Card Two</div> </pearson-card> <pearson-card> <div>Card Three</div> </pearson-card> <pearson-card> <div>Card Four</div> </pearson-card></div>
#
Column LayoutTo change the view inside the grid to a stacked view, add the attribute stacked
to the <pearson-card>
.
<pearson-card stacked>
#
Toggle LayoutYou can easily switch between a row view, and a column view by toggling the attribute stacked
in the component, while wrapped in the .gr-grid-container
class.
const button = document.querySelector('#toggleTrigger'), cards = document.querySelectorAll('#toggleCard pearson-card');
if (cards.length > 0) { button.innerHTML = "List View" button.addEventListener('click', event => { cards.forEach(card => { if (card.hasAttribute('stacked')) { card.removeAttribute('stacked') button.innerHTML = "List View"; } else { card.setAttribute('stacked', true) button.innerHTML = "Row View"; } }) })}
#
APIAll attributes in this API are optional.
Attribute | Type | Default | Description |
---|---|---|---|
stacked | Bool | unset | When multiple cards are displayed, this changes the layout from a row view to a stacked column view. |
#
EventsThis is a display wrapper only and has no events associated with it.
#
HTML MarkupDo you want to customize your card? You can use the markup provided below as a starting point, and style the card however you like..
<div class="card-container"> <div class="card"> Content goes here... </div></div>