image

A flexible card component with optional images, container-based layouts, and a configurable color palette. Use it for category links, services, resources, or any collection that needs a consistent card design without making every card look identical.

The same component works on its own or inside an Etch loop. Its layout responds to the individual card’s width, and its automatic colors come from a palette you define. Content, display controls, and custom styling are organized into two groups: Card Settings and Card Values.

Getting started

Copy the complete contents of Flexi-Card-Cinque-Terre.clipboard.txt and paste into Etch. This adds the component and its bundled styles and JavaScript. No separate global script installation is needed.

Open Card Values to enter the title, description, image, and link. Then use Card Settings to choose the wrapper tag, heading level, visible elements, and background behavior.

Choose div for a standalone card. Choose li when placing the component directly inside a ul or ol. The wrapper belongs to the component, so you don’t need an additional list-item wrapper.

The component does not create a grid. Use your own grid or list to control columns and spacing between cards.

Card settings

PropertyTypePurpose
cardSettings.wrapperTagSelectRenders the outer wrapper as li or div. Component default: li.
cardSettings.headingLevelSelectSets the title to h2, h3, or h4. Default: h3.
cardSettings.showImageBooleanShows or removes the image.
cardSettings.showLedeBooleanAllows the description to display when text is present.
cardSettings.showLinkBooleanAllows the link to display when a URL is present.
cardSettings.hasBgBooleanApplies the component’s background, padding, and border radius.
cardSettings.autoColorsBooleanAssigns a color from the supplied palette. Default: enabled.
cardSettings.bgColor.colorOptionsRepeaterDefines the palette using Name and CSS Color fields.
cardSettings.bgColor.colorTextOverrides the palette assignment with a palette name or CSS color. Use none for automatic/default behavior.
cardSettings.styleHooksGroupProvides Class properties for styling individual parts of the card.

The image, description, link, and background toggles default to enabled. The supplied paste-ready demonstration instance hides the image until you select one and uses a div wrapper.

Card values

PropertyTypePurpose
cardValues.titleTextTextCard heading.
cardValues.ledeTextTextOptional description below the heading.
cardValues.imageSourceWordPress mediaSelects the card image.
cardValues.link.linkTextTextVisible link label.
cardValues.link.linkUrlTextLink destination.
cardValues.link.ariaLabelTextOptional accessible label when the visible text needs more context.

You can enter these values manually or connect them to dynamic data on a component instance. The conditional sections in the property panel organize the controls; they do not add extra segments to the property paths above.

Define your own palette

Under Card Settings → BG Color → Color Options, add a name and CSS value for each color:

NameCSS Color
Pinkvar(--secondary-ultra-light)
Greenvar(--tertiary-ultra-light)
Tancolor-mix(in oklch, var(--neutral) 12%, transparent)

You can use named colors, hex, RGB, OKLCH, CSS variables, or color-mix(). Names label an explicit color; the CSS value controls its appearance.

The script uses the first six nonempty, syntactically valid entries. It ignores extra rows, even if the repeater panel lets you add more. CSS variables must exist in your stylesheet; a syntactically valid var() reference does not guarantee that the variable has a value.

How automatic colors work

Automatic coloring uses shuffled batches. With three palette entries, each complete batch of three eligible cards receives every entry once before the next batch begins. With five entries, the batch size becomes five.

Eligible cards share a parent and an identical palette, have Auto Colors and Has BG enabled, and have no valid explicit override. No attribute or companion component is required on the parent.

The shuffle is deterministic. A given palette and card order produces the same assignments on reload, while successive batches can have different orders. Reordering cards or changing the palette can change the assignments.

The algorithm avoids repeating an identical color at the boundary between batches when a different color is available. It does not measure the grid’s columns or guarantee different colors above and below each card. An incomplete final batch uses only part of the palette.

image
Color randomization

Set an explicit color

Enter a palette name such as Pink in Explicit Color, or enter a CSS value directly:

var(--primary-ultra-light)
HTML

Palette-name matching is case-insensitive. Explicitly colored cards are excluded from automatic batches. Set the field back to none to restore automatic coloring.

With automatic colors disabled, a card uses the first valid palette entry as its default. If neither a valid palette nor a valid explicit color is available, its background is transparent. Has BG still controls whether the default padding and radius apply.

Responsive layouts with container queries

The outer .cqt-wrapper is always an inline-size query container. The card stacks its image above its content in a narrow space, then switches to a horizontal layout when its container reaches the existing to-rem(700px) threshold.

This responds to the card’s available space rather than the browser viewport. A card in a narrow column can remain stacked while another card on the same page uses the horizontal layout.

At the wider layout, the image wrapper takes 40% by default, and the content takes the remaining space. With the image disabled, the content takes up the full available width.

The query container is part of the component, not an optional setting. To change the trigger, update the matching thresholds in the card, media-wrapper, and content-wrapper rules together. The threshold lives in CSS; it is not currently a component property. You can add additional query conditions there when needed.

Styling the component

All component classes use the short cqt namespace:

ElementClass
Dynamic outer wrapper.cqt-wrapper
Inner article/layout.cqt
Image wrapper.cqt__media-wrapper
Image.cqt__media
Content wrapper.cqt__content-wrapper
Heading.cqt__title
Description.cqt__lede
Link.cqt__link

Use these classes to change every instance. For an individual instance or variant, add your own classes through Card Settings → Custom Styles. Each element has separate Class properties listed above. Your classes are appended to the built-in classes, so the component retains its structural hooks.

CSS custom properties

Apply these variables through a custom wrapper class or an ancestor. They use fallback values rather than fixed defaults, so you can make common adjustments without competing with the component’s selectors.

VariableDefaultControls
--cqt-paddingvar(--space-s)Background padding.
--cqt-radiuscalc(var(--radius) * 1.25)Background radius.
--cqt-gapvar(--card-gap)Space between image and content.
--cqt-content-gapcalc(var(--card-gap) - 2px)Space between content elements.
--cqt-content-paddingto-rem(4px)Inline content padding.
--cqt-image-ratio16 / 9Image aspect ratio.
--cqt-link-sizecalc(var(--text-s) - 1px)Link font size.
--cqt-link-weight600Link font weight.
--cqt-media-width40%Image share in the horizontal layout.

For example, add resource-card through Wrapper Classes:

.resource-card {
  --cqt-padding: 2rem;
  --cqt-radius: 0.5rem;
  --cqt-gap: 1.5rem;
  --cqt-image-ratio: 4 / 3;
  --cqt-link-weight: 500;
}
CSS

Typography can be styled directly. Add resource-card-title through Title Classes:

.resource-card-title {
  font-family: Georgia, serif;
  font-size: 2rem;
  line-height: 1.15;
}
CSS

Direct CSS overrides follow the normal cascade. For equally specific rules, the later rule wins. Background-state selectors include an attribute selector, so using the exposed padding and radius variables is usually easier than overriding those declarations directly. The component does not use !important.

Using the card in a loop

Place the component inside your Etch loop and bind its Card Values to that loop’s data. For a category loop, the title can use {item.name} and the description can use {item.description}. Map the image and destination to the fields available in your own loop output.

For a list, use this rendered structure:

<ul class="your-grid-class">
  <li class="cqt-wrapper">
    <article class="cqt">...</article>
  </li>
  <li class="cqt-wrapper">
    <article class="cqt">...</article>
  </li>
</ul>
HTML

Keep the component wrappers as siblings when you want automatic colors balanced across the collection. An additional external wrapper around each component creates a separate parent for each card, so each becomes its own color group.

Accessibility and content

Choose a heading level that fits the surrounding page, use descriptive link text, and check the image’s alternative text in the rendered output. If you provide an ARIA label, remember that it replaces the visible link text as the accessible name; include that visible wording in the label.

Custom backgrounds can change text contrast. Check the heading, description, and link against every color in your palette. The color script assigns backgrounds; it does not calculate contrasting text colors.

Troubleshooting

SymptomWhat to check
No automatic colorConfirm Auto Colors and Has BG render as true, and the palette has valid entries.
A card ignores the shuffleCheck for an explicit palette name or CSS color override.
Every card receives the same colorCheck that the component wrappers share a parent and use the same palette. Also check for duplicate palette values.
No horizontal layoutThe individual wrapper may still be narrower than the query threshold. A wide viewport alone does not trigger it.
A custom style does not winCheck the target element, selector specificity, stylesheet order, or use an exposed CSS variable.
A CSS variable color is missingConfirm the variable exists on the card or an ancestor.
Cards inserted later have no automatic colorThe script initializes on page load. AJAX-inserted cards need initialization after insertion.

On the rendered frontend, inspect .cqt-wrapper. An automatically colored card should have data-auto-colors="true", data-has-bg="true", and a script-assigned data-auto-color value. The selected CSS value appears in the inline --cqt-auto-bg variable. A manual override uses --cqt-explicit-bg instead.

Requirements and implementation notes

The supplied styling uses Automatic CSS variables and its to-rem() syntax. On a site without that setup, replace those references with your own tokens and supported values. The component also relies on CSS nesting, container queries, and JavaScript to automatically assign a palette.

If JavaScript is unavailable, automatic and explicit palette resolution do not run. The wrapper’s background falls back to transparent, while the content and CSS layout remain available.

The package has passed local data and JavaScript checks. Its import and rendered appearance still need verification in the target Etch installation.