Cards

Basic container styles for creating basic cards including a link card component.

Examples (anchor)

The cards expect the existence of basic reset styles for font styling and typography properties. The typography style module provides this but the styles should work with any reset/normalize document used.

Default (anchor)

Card title

The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.

Link to action
Examples HTML
<div class="card">
  <h2>Card title</h2>
  <p>The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.</p>
  <a href="#">Link to action</a>
</div>

<div class="card-link">
  <h2>Link card</h2>
  <p>The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.</p>
  <a href="#">Link to action</a>
</div>

Fixed light and dark (anchor)

Card title

The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.

Link to action

Card title

The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.

Link to action
Examples HTML
<div class="card card-light">
  <h2>Card title</h2>
  <p>The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.</p>
  <a href="#">Link to action</a>
</div>

<div class="card-link card-light">
  <h2>Link card</h2>
  <p>The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.</p>
  <a href="#">Link to action</a>
</div>

<div class="card card-dark">
  <h2>Card title</h2>
  <p>The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.</p>
  <a href="#">Link to action</a>
</div>

<div class="card-link card-dark">
  <h2>Link card</h2>
  <p>The quick brown fox jumps over the lazy dog followed by the five boxing wizards jumping quickly.</p>
  <a href="#">Link to action</a>
</div>

Using the module (anchor)

To use the module load the StyleMods scss directory as follows (changing the path to suit the source files location as required) then include the Sass mixin anywhere below.

custom.scss
@use "stylemods/scss" as *;
@include cards-css;

Source code (anchor)

See customizing for information about using the Sass and CSS variables in the source code to customize the styles, and Sass functionality (on the using StyleMods page) for other ways to use the variables to create custom styles.

cards.scss
// ---------------------------------------------------------- 
// Cards
// ----------------------------------------------------------
$card-text-color:             var(--card-text, CanvasText) !default; 
$card-padding-block:          var(--card-py, 1rem) !default;
$card-padding-inline:         var(--card-px, 1rem) !default;
$card-border-color:           var(--card-bd-color, color-mix(in srgb, CanvasText 15%, Canvas)) !default;
$card-radius:                 var(--card-radius, 0.188rem) !default;
$card-background-color:       var(--card-bg, Canvas) !default;
$card-link-hover-text-color:  var(--card-text-hover, CanvasText) !default;
$card-link-hover-background:  var(--card-hover, color-mix(in srgb, CanvasText 4%, Canvas)) !default;
$card-link-focus-width:       var(--card-focus, 0.188rem) !default;
$card-link-focus-color:       var(--card-focus-color, color-mix(in srgb, CanvasText 15%, Canvas)) !default;

@mixin cards-css {

:where(.card, .card-link) {
  color: $card-text-color; 
  max-inline-size: var(--card-width); 
  padding-block: $card-padding-block;
  padding-inline: $card-padding-inline;
  border: 1px solid $card-border-color;
  border-radius: $card-radius;
  background-color: $card-background-color;
}

:where(.card, .card-link) * {
  text-align: var(--card-align, initial);
  text-wrap: var(--card-wrap, initial);
}

:where(.card, .card-link) p:not(:last-child) {
  margin-block-end: var(--card-p-mb, 0.5rem);
}

:where(.card-link) {
  position: relative;
}

:where(.card :last-child, .card-link :last-child)  {
  margin-block-end: 0;
}

:where(.card, .card-link:is(:last-child))  {
  margin-block-end: 0;
}

.card-link a:after {
  content: "";
  display: block;
  position: absolute;
  inset: 0;
}

:where(.card-link :focus-visible) {
  outline: none;
}

:where(.card-link:is(:focus-within, :hover)) {
  color: $card-link-hover-text-color;
  background-color: $card-link-hover-background;
  cursor: pointer;
}

:where(.card-link:focus-within) {
  outline: $card-link-focus-width solid $card-link-focus-color;
}

:where(.card, .card-link) img {
  display: block;
  max-inline-size: 100%;
  object-fit: cover;
  aspect-ratio: var(--img-ratio, auto);
  block-size: 100%;
  margin-block-end: var(--card-img-mb, 0.75rem);
}

.card-light {
  color-scheme: light;
}

.card-dark {
  color-scheme: dark;
}


.card-link-light {
  color-scheme: light;
}

.card-link-dark {
  color-scheme: dark;
}

} // end cards-css