Cards
Quasar Cards are a great way to display important pieces of content, and are quickly emerging as a core design pattern for Apps. They’re a great way to contain and organize information, while also setting up predictable expectations for the user. With so much content to display at once, and often so little screen real-estate, Cards have fast become the design pattern of choice for many companies, including the likes of Google and Twitter.
Quasar Cards are a collection of components that you can use, based on the needs. It’s all about being creative. Experiment with different Web Components by embedding them in Card components to create awesome results.
Installation
Edit /quasar.conf.js
:framework: {
components: [
'QCard',
'QCardTitle',
'QCardMain',
'QCardMedia',
'QCardSeparator',
'QCardActions'
]
}
Basic Usage
Familiarize yourself with Card components with the examples below. The only requirement is that QCard needs to wrap all the other ones. Everything else is optional and can be inserted into your template anywhere as long as they are direct children of QCard.
Following are Vue properties of QCard component:
Vue Property | Type | Description |
---|---|---|
square |
Boolean | Squared borders instead of round ones. |
flat |
Boolean | Remove shadow. |
inline |
Boolean | Make it inline. Also set a CSS width to work. Take a look at Grid example on the “More Examples” section. |
color |
String | One color from Quasar Color Palette. |
text-color |
String | Override color of text, one from Quasar Color Palette. |
<!-- An basic example --> |
A more complex example:<q-card inline style="width: 500px">
<q-card-media>
<img src="~assets/donuts.png">
</q-card-media>
<q-card-title>
Cafe Basilico
<q-rating slot="subtitle" v-model="stars" :max="5" />
<div slot="right" class="row items-center">
<q-icon name="place" /> 250 ft
</div>
</q-card-title>
<q-card-main>
<p>$・Italian, Cafe</p>
<p class="text-faded">Small plates, salads & sandwiches in an intimate setting.</p>
</q-card-main>
<q-card-separator />
<q-card-actions>
<q-btn flat round dense icon="event" />
<q-btn flat label="5:30PM" />
<q-btn flat label="7:30PM" />
<q-btn flat label="9:00PM" />
<q-btn flat color="primary" label="Reserve" />
</q-card-actions>
</q-card>
Card Title (QCardTitle)
QCardTitle has three main areas (all are optional): title, subtitle (“subtitle” slot) and right side (“right” slot).
Note that you can set title and subtitle as overlay on an image or video through a QCardMedia component too (see QCardMedia section).
<q-card-title> |
Card Main Content (QCardMain)
QCardMain defines an area containing the main Card content, like description, details or anything you need outside of the other Card component’s purpose.
<q-card-main> |
Card Actions (QCardActions)
Cards can have some actions (buttons) attached to them.
Vue Property | Type | Description |
---|---|---|
vertical |
Boolean | Stack actions vertically |
align |
String | One of ‘start’, ‘center’, ‘end’, ‘around’, ‘between’ which aligns buttons in respect to the actions container |
<!-- Horizontal actions --> |
Card Media (QCardMedia)
Cards can also contain media elements: images, videos (through QVideo) or a parallax (through QParallax). This can be done through QCardMedia component, which supports an optional overlay too (for things like title and/or subtitle).
Vue Property | Type | Description |
---|---|---|
overlay-position |
String | One of ‘top’, ‘bottom’ or ‘full’ which sets the position of overlay on top of media element. |
<!-- Displaying an image --> |
Now let’s see how we can add overlays too (through “overlay” slot):<q-card-media>
<img src="~assets/mountains.jpg">
<!-- Notice the slot="overlay" -->
<q-card-title slot="overlay">
Title
<span slot="subtitle">Subtitle</span>
</q-card-title>
</q-card-media>
<!--
Overlay at top of media elements.
Notice overlay-position="top"
-->
<q-card-media overlay-position="top">
<img src="~assets/mountains.jpg">
<!-- Notice the slot="overlay" -->
<q-card-title slot="overlay">
Title
<span slot="subtitle">Subtitle</span>
</q-card-title>
</q-card-media>
<!--
Overlay on full area of media elements
Notice overlay-position="full"
-->
<q-card-media overlay-position="full">
<img src="~assets/mountains.jpg">
<!-- Notice the slot="overlay" -->
<q-card-title slot="overlay">
Title
<span slot="subtitle">Subtitle</span>
</q-card-title>
</q-card-media>
Card Inner Separator
You can choose to add a separator between Card components, which is basically a horizontal thin line, by adding QCardSeparator:
<q-card> |
Some More Examples
Coloring Cards
Use colors from Quasar Color Palette to set a color for your Cards.
<q-card color="primary"> |
Lists on Cards
Place a QList with its QItems at root of your QCard, like this:
<q-card> |
There’s also the possibility to create a nice header for your Cards with an image / avatar, a person name and some quick details. In this example, we skip using QCardList:
<q-card> |
Making a Grid of Cards
In order to make a grid of Cards you need to use the inline
property of QCard component and set a width for your Cards.
<div> |
Card with Collapsibles
Since Collapsibles are List items too, it makes sense to use a QList component to encapsulate them. Also, imagine a Card with Collapsibles containing Cards. Inception :)
<q-card> |