My first card
Nothing fancy yet!
ButtonStill work in progress.
Cards combine imagery, a short description, and a link or call-to-action.
I've avoided styling the content of the card. I'd prefer card content to be driven by standard building blocks, like the rest of the DS. We could provide utility classes to size things like card headings. This would be much more flexible and encourage emergent use.
Cards themselves have no explicit size. They flow into their container. This makes them useful in many different scenarios.
Here's a basic card, all alone.
Nothing fancy yet!
ButtonNothing fancy yet!
Button<ca-card>
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
<article>
<h3><a href="#">My first card</a></h3>
<p>Nothing fancy yet!</p>
<a href="#" class="ca-button ca-button-magenta">Button</a>
</article>
</ca-card>
A card consists of two possible elements.
img
or svg
element.article
, div
, or section
, depending upon
desired semantics.Cards have no explicit size themselves. By default, they expand to their container.
To size a single card, just add a max-width
.
The max-width
limits the size of the card.
The max-width
limits the size of the card.
<ca-card style="max-width: 31rem">
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
<article>
<h3><a href="#">My first card, constrained</a></h3>
<p>The <code>max-width</code> limits the size of the card.</p>
</article>
</ca-card>
In many real-world use cases, we will be displaying many cards together, in list-like structures.
One way to do this is with our own ca-mesh
component.
Resize the window to see how the cards respond to changes in the grid.
Note the size="medium"
attributes. This helps lock the images into consistent size across all
cards.
It's all aligned.
Resize the window to see how the cards respond to changes in the grid.
Note the size="medium"
attributes. This helps lock the
images into consistent size across all cards.
It's all aligned.
<ca-mesh>
<ca-card size="medium">
<img
src="https://live.staticflickr.com/5707/30956223351_b42f440856_o_d.jpg"
alt="Half dome"
/>
<div>
<h3><a href="#">Grid card 1</a></h3>
<p>
Resize the window to see how the cards respond to changes in the grid.
</p>
</div>
</ca-card>
<ca-card size="medium">
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
<article>
<h3><a href="#">Grid card 2</a></h3>
<p>
Note the <code>size="medium"</code> attributes. This helps lock the
images into consistent size across all cards.
</p>
</article>
</ca-card>
<ca-card size="medium">
<img
src="https://live.staticflickr.com/5609/15596534729_9c240ff83a_b.jpg"
alt="Brown bear"
/>
<div>
<h3><a href="#">Grid card 3</a></h3>
<p>It's all aligned.</p>
</div>
</ca-card>
</ca-mesh>
A card is nearly always displayed with friends, in a grid-like structure. We usually want every card to be the same size, nicely aligned.
Below, we use the ca-mesh
component's sizing capabilities to change the flow of all cards together.
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
<!-- The --cell-width variable is a function of the ca-mesh component. -->
<ca-mesh style="--cell-width: 15rem">
<ca-card>
<img
src="https://live.staticflickr.com/5609/15596534729_9c240ff83a_b.jpg"
alt="Brown bear"
/>
<div>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
</ca-card>
<ca-card>
<img
src="https://live.staticflickr.com/5609/15596534729_9c240ff83a_b.jpg"
alt="Brown bear"
/>
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
<ca-card>
<img
src="https://live.staticflickr.com/5609/15596534729_9c240ff83a_b.jpg"
alt="Brown bear"
/>
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
<ca-card>
<img
src="https://live.staticflickr.com/5609/15596534729_9c240ff83a_b.jpg"
alt="Brown bear"
/>
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
<ca-card>
<img
src="https://live.staticflickr.com/5609/15596534729_9c240ff83a_b.jpg"
alt="Brown bear"
/>
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
</ca-mesh>
Many scenarios call for cards to be displayed within a semantic ul
or ol
list. No
problem.
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
<ca-mesh>
<ul class="meshify">
<li>
<ca-card size="medium">
<img
src="https://live.staticflickr.com/5609/15596534729_9c240ff83a_b.jpg"
alt="Brown bear"
/>
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
</li>
<li>
<ca-card size="medium">
<img
src="https://live.staticflickr.com/5707/30956223351_b42f440856_o_d.jpg"
alt="Half dome"
/>
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
</li>
<li>
<ca-card size="medium">
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
</li>
</ul>
</ca-mesh>
<!-- Note our use of the grid class here. -->
Images will automatically fit the card with an object-fit
of cover
. This can be altered by
applying a utility class to the image.
Let's stretch out this image with the fit-fill
class. Why not?
Let's stretch out this image with the fit-fill
class. Why
not?
<ca-card>
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
class="fit-fill"
/>
<article>
<h3><a href="#">Using fit</a></h3>
<p>
Let's stretch out this image with the <code>fit-fill</code> class. Why
not?
</p>
</article>
</ca-card>
Here's a list of available utility classes.
Class | Effect |
---|---|
fit-cover |
Default. Instructs the image to fill all available space, without breaking aspect ratio. Some content may be hidden along the edges. |
fit-contain |
Instructs the image to expand, but without breaking aspect ratio or hiding anything. This may result in some margin around the image. |
fit-fill |
Instructs the image to fill all available space by stretching itself, breaking aspect ratio. |
Padding can be added around the image if desired. Use utility classes.
Add CSS or utility classes to alter the padding.
Add CSS or utility classes to alter the padding.
<ca-card class="padding-2">
<img
class="rounded"
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
<article class="padding-y-start-3 padding-y-end-0 padding-x-1">
<h3><a href="#">Using padding</a></h3>
<p>Add CSS or utility classes to alter the padding.</p>
</article>
</ca-card>
The card is a base. It's flexible. Add your own CSS or utility classes to make it yours.
The interactive
attribute can set visual hover effects on the card.
By default, this will raise the whole card when a link or button is hovered.
When hovering a link, the whole card will rise.
When hovering a link, the whole card will rise.
<ca-card interactive="">
<img
src="https://live.staticflickr.com/5707/30956223351_b42f440856_o_d.jpg"
alt="Half dome"
/>
<div>
<h3><a href="#">Interactive hover on the links</a></h3>
<p>When hovering a link, the whole card will rise.</p>
</div>
</ca-card>
With interactive="full"
, we can make the whole card clickable.
Through the magic of CSS, the whole card is now clickable.
Through the magic of CSS, the whole card is now clickable.
<ca-card interactive="full">
<img
src="https://live.staticflickr.com/5707/30956223351_b42f440856_o_d.jpg"
alt="Half dome"
/>
<div>
<h3><a href="#">Fully clickable card</a></h3>
<p>Through the magic of CSS, the whole card is now clickable.</p>
</div>
</ca-card>
The shadow
attribute adds depth.
Catch some shade.
Catch some shade.
<ca-card shadow="">
<img
src="https://live.staticflickr.com/5707/30956223351_b42f440856_o_d.jpg"
alt="Half dome"
/>
<div>
<h3><a href="#">The shadow card</a></h3>
<p>Catch some shade.</p>
</div>
</ca-card>
It's even better when used alongside interactive
.
Catch some (raised) shade.
Catch some (raised) shade.
<ca-card interactive="full" shadow="">
<img
src="https://live.staticflickr.com/5707/30956223351_b42f440856_o_d.jpg"
alt="Half dome"
/>
<div>
<h3><a href="#">The interactive shadow card</a></h3>
<p>Catch some (raised) shade.</p>
</div>
</ca-card>
Images are optional in our cards.
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
Lorem ipsum dolor sit amet, consectetur
<ca-mesh>
<ca-card>
<div>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
</ca-card>
<ca-card>
<div>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
</ca-card>
<ca-card>
<!-- But the content container will still work too. Here we use article. -->
<article>
<h3><a href="#">Card heading</a></h3>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</article>
</ca-card>
</ca-mesh>
Cards can be tipped over, placing images on the side instead.
Use the flow="horizontal"
attribute.
The flow="horizontal"
attribute puts the image on the side.
The flow="horizontal"
attribute puts the image on the side.
<ca-card flow="horizontal" size="small">
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
<article>
<h3><a href="#">Using direction</a></h3>
<p>
The <code>flow="horizontal"</code> attribute puts the image on the side.
</p>
</article>
</ca-card>
To change the direction of the responsive flip on mobile, use flow="horizontal-reverse"
.
flow="horizontal-reverse"
flips vertical orientation on mobile.
flow="horizontal-reverse"
flips vertical orientation on
mobile.
<ca-card flow="horizontal-reverse" size="small">
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
<article>
<h3><a href="#">Flipping direction</a></h3>
<p>
<code>flow="horizontal-reverse"</code> flips vertical orientation on
mobile.
</p>
</article>
</ca-card>
To put the image at the end of the card, just switch the position of the image element.
By changing the position of the img
element, we we can put the image at bottom of the card.
By changing the position of the img
element, we we can put
the image at bottom of the card.
<ca-card size="medium">
<article>
<h3><a href="#">Flipping position</a></h3>
<p>
By changing the position of the <code>img</code> element, we we can put
the image at bottom of the card.
</p>
</article>
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
</ca-card>
Works with horizontal cards too.
We can put the image on the right in horizontal cards too.
We can put the image on the right in horizontal cards too.
<ca-card flow="horizontal" size="small">
<article>
<h3><a href="#">Flipping position, horizontal</a></h3>
<p>We can put the image on the right in horizontal cards too.</p>
</article>
<img
src="https://live.staticflickr.com/8628/16622486169_087756b818_b.jpg"
alt="California poppy flower"
/>
</ca-card>