Card One
This is the description for the first card
h2
, the image alt text isn't skipped over, as it logically belongs to the topic of
the h2
.h2
.
This link, therefore, has an ::after
pseudo-element that covers the card.::after
by positioning it relatively.cards.js
javascript file, which allows the user to both select the text or click through--if the
click is < 200ms, the link is followed. Otherwise, the text can be selected.:hover
style for the card is applied when anything within the card is focused.:hover
style is removed from the header link as the card itself is highlighted on hover.Simple cards with footers that have an additional link. The footer
is optional.
_cmp.cards.scss
cards.js
This is the description for the first card
Description of the second item goes here
A longer description of the third item, the paragraph is just a bit longer here
<div class="cmp-cards">
<article class="cmp-cards__card">
<div class="cmp-cards__text">
<header class="cmp-cards__header">
<h2><a class="cmp-cards__header-link" href="#">Card One</a></h2>
</header>
<p class="cmp-cards__description">This is the description for the first card</p>
<footer class="cmp-cards__footer">
<small class="cmp-cards__byline">By <a class="cmp-cards__byline-link" href="#">Someone</a></small>
</footer>
</div>
<div class="cmp-cards__image">
<img src="https://picsum.photos/400/200" alt="Description of the image">
</div>
</article>
<article class="cmp-cards__card">
<div class="cmp-cards__text">
<header class="cmp-cards__header">
<h2><a class="cmp-cards__header-link" href="#">Card Two</a></h2>
</header>
<p class="cmp-cards__description">Description of the second item goes here</p>
</div>
<div class="cmp-cards__image">
<img src="https://picsum.photos/400/200" alt="Description of the image">
</div>
</article>
<article class="cmp-cards__card">
<div class="cmp-cards__text">
<header class="cmp-cards__header">
<h2><a class="cmp-cards__header-link" href="#">Card Three</a></h2>
</header>
<p class="cmp-cards__description">A longer description of the third item, the paragraph is just a bit longer here</p>
<footer class="cmp-cards__footer">
<small class="cmp-cards__byline">By <a class="cmp-cards__byline-link" href="#">Someone Else</a></small>
</footer>
</div>
<div class="cmp-cards__image">
<img src="https://picsum.photos/400/200" alt="Description of the image">
</div>
</article>
</div>
:focus
style is removed from the header link and, instead, when focused it applies the
button's :hover
style.aria-hidden
is true
.aria-hidden="true"
, but in this example the focus is actually on the link
in the header. This ensures that the text associated and read with the link is relevant while visually allowing
the user to tab through the CTA button. The tabindex="-1"
allows the user to actually skip over focusing the
CTA button._cmp.cards.scss
cards.js
This is the description for the first card
Description of the second item goes here
A longer description of the third item, the paragraph is just a bit longer here
<div class="cmp-cards cmp-cards--ctas">
<article class="cmp-cards__card">
<div class="cmp-cards__text">
<header class="cmp-cards__header">
<h2><a class="cmp-cards__header-link" href="#">Card One</a></h2>
</header>
<p class="cmp-cards__description">This is the description for the first card</p>
<footer class="cmp-cards__footer">
<a class="cmp-cards__cta" tabindex="-1" href="#" aria-hidden="true">Read more →</a>
<small class="cmp-cards__byline">By <a class="cmp-cards__byline-link" href="#">Someone</a></small>
</footer>
</div>
<div class="cmp-cards__image">
<img src="https://picsum.photos/400/200" alt="Description of the image">
</div>
</article>
<article class="cmp-cards__card">
<div class="cmp-cards__text">
<header class="cmp-cards__header">
<h2><a class="cmp-cards__header-link" href="#">Card Two</a></h2>
</header>
<p class="cmp-cards__description">Description of the second item goes here</p>
<footer class="cmp-cards__footer">
<a class="cmp-cards__cta" tabindex="-1" href="#" aria-hidden="true">Read more →</a>
<small class="cmp-cards__byline">By <a class="cmp-cards__byline-link" href="#">Someone Else</a></small>
</footer>
</div>
<div class="cmp-cards__image">
<img src="https://picsum.photos/400/200" alt="Description of the image">
</div>
</article>
<article class="cmp-cards__card">
<div class="cmp-cards__text">
<header class="cmp-cards__header">
<h2><a class="cmp-cards__header-link" href="#">Card Three</a></h2>
</header>
<p class="cmp-cards__description">A longer description of the third item, the paragraph is just a bit longer here</p>
<footer class="cmp-cards__footer">
<a class="cmp-cards__cta" tabindex="-1" href="#" aria-hidden="true">Read more →</a>
<small class="cmp-cards__byline">By <a class="cmp-cards__byline-link" href="#">Someone</a></small>
</footer>
</div>
<div class="cmp-cards__image">
<img src="https://picsum.photos/400/200" alt="Description of the image">
</div>
</article>
</div>