Powered by NeGD | MeitY Government of India® UX4G
Card
UX4G’s cards provide a flexible and extensible content container with multiple variants and options.
About #
A flexible and expandable content container is a card. It offers options for headers and footers, a range of information, background colors that are appropriate for the context, and strong display options. Cards take the role of our previous panels, wells, and thumbnails if you are familiar with UX4G. As modifier classes for cards, similar functionality to that of those components is accessible.
Example #
Cards are constructed with the least amount of markup and styles possible while yet managing to offer a substantial amount of control and customization. They are easily alignable and blend in with other UX4G components thanks to their flexbox construction. Use spacing tools as necessary because they don't come with margins by default.
The basic card with mixed content and a fixed width is demonstrated here. Cards naturally cover the entire width of their parent element because they don't have a set width to begin with. Thanks to many sizing possibilities, this is easily customizable.
<div class="card" styles="width: 18rem;"><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div>
RESULT
Card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Go somewhereContent types #
Cards can include a variety of material, such as text, list groups
, links, photos
, and more. Examples of what is supported are shown below.
Body #
The .card-body
is a card's fundamental component. Use it any time you require a padded area within a card.
<div class="card"><div class="card-body">This is some text within a card body.</div></div>
RESULT
Titles, text, and links #
Developer can utilize card titles by appending .card-title
to a <h*>
element. The same method is used to add and position links by appending .card-link
to an <a>
tag.
Developer can utilize subtitles by appending a .card-subtitle
tag to a
tag. The card title and subtitle are beautifully aligned if the .card-title
and .card-subtitle
items are placed in a .card-body item.
<div class="card" styles="width: 18rem;"><div class="card-body"><h5 class="card-title">Card title</h5><h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6><p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p><a href="#" class="card-link">Card link</a><a href="#" class="card-link">Another link</a></div></div>
RESULT
Card title
Card subtitle
Some quick example text to build on the card title and make up the bulk of the card's content.
Card linkAnother linkImages #
.card-img-top
adds a top-level picture to the card. Text can be added to the card using .card-text
. The usual HTML elements can also be used to style text inside of .card-text
.
Add an optional header and/or footer within a card.
<div class="card" style="width: 18rem;">
<div class="card-header d-flex justify-content-between border-bottom-0">
<h6 class="card-title m-0">Header</h6>
<i class="fa fa-ellipsis-v"></i>
</div>
<img src="..." alt="img" />
<div class="card-body">
<h5 class="card-title mb-2">Card title</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">Card subtitle</h6>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
<div class="card-footer border-top-0 d-flex justify-content-end gap-3">
<button class="btn btn-outline-primary">Cancel</button>
<button class="btn btn-primary">Button</button>
</div>
</div>
<div class="card shadow-xl" style="width: 18rem;">
<div class="card-header d-flex justify-content-between border-bottom-0">
<h6 class="card-title m-0">Header</h6>
<i class="fa fa-ellipsis-v"></i>
</div>
<img src="..." alt="img" />
<div class="card-body">
<h5 class="card-title mb-2">Card title</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">Card subtitle</h6>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
<div class="card-footer border-top-0 d-flex justify-content-end gap-3">
<button class="btn btn-outline-primary">Cancel</button>
<button class="btn btn-primary">Button</button>
</div>
</div>
RESULT
Header
Card title
Card subtitle
Some quick example text to build on the card title and make up the bulk of the card's content.
Header
Card title
Card subtitle
Some quick example text to build on the card title and make up the bulk of the card's content.
Horizontal #
Cards can be made horizontal
in a mobile-friendly and responsive fashion by combining grid and utility classes. In the example below, there is a use of col-md-* classes to make the card horizontal
at the md breakpoint and the .g-0
class to eliminate the grid gutters. Depending on the information in the card, additional adjustments might be required
<div class="card" style="width: 40rem;">
<div class="card-header d-flex justify-content-between border-bottom-0">
<h6 class="card-title m-0">Header</h6>
<i class="fa fa-ellipsis-v"></i>
</div>
<div class="row g-0">
<div class="col-sm-5">
<img src="..." class="img-fluid rounded-start" alt="img"/>
</div>
<div class="col-sm-7">
<div class="card-body">
<h5 class="card-title mb-2">Card title</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">Card subtitle</h6>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
<div class="card-footer border-top-0 d-flex justify-content-end gap-3">
<button class="btn btn-outline-primary">Cancel</button>
<button class="btn btn-primary">Button</button>
</div>
</div>
</div>
</div>
<div class="card shadow-xl" style="width: 40rem;">
<div class="card-header d-flex justify-content-between border-bottom-0">
<h6 class="card-title m-0">Header</h6>
<i class="fa fa-ellipsis-v"></i>
</div>
<div class="row g-0">
<div class="col-sm-5">
<img src="..." class="img-fluid rounded-start" alt="img"/>
</div>
<div class="col-sm-7">
<div class="card-body">
<h5 class="card-title mb-2">Card title</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">Card subtitle</h6>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
<div class="card-footer border-top-0 d-flex justify-content-end gap-3">
<button class="btn btn-outline-primary">Cancel</button>
<button class="btn btn-primary">Button</button>
</div>
</div>
</div>
</div>
RESULT
Header
Card title
Card subtitle
Some quick example text to build on the card title and make up the bulk of the card's content.
Header
Card title
Card subtitle
Some quick example text to build on the card title and make up the bulk of the card's content.
List groups #
Create lists of content in a card with a flush list group.
<div class="card" styles="width: 18rem;"><ul class="list-group list-group-flush"><li class="list-group-item">An item</li><li class="list-group-item">A second item</li><li class="list-group-item">A third item</li></ul></div>
RESULT
- An item
- A second item
- A third item
<div class="card" styles="width: 18rem;"><div class="card-header">Featured</div><ul class="list-group list-group-flush"><li class="list-group-item">An item</li><li class="list-group-item">A second item</li><li class="list-group-item">A third item</li></ul></div>
RESULT
- An item
- A second item
- A third item
<div class="card" styles="width: 18rem;"><ul class="list-group list-group-flush"><li class="list-group-item">An item</li><li class="list-group-item">A second item</li><li class="list-group-item">A third item</li></ul><div class="card-footer">Card footer</div></div>
RESULT
- An item
- A second item
- A third item
Kitchen sink#
Create the card you need by combining different content categories, or just put everything in there. Below, a fixed-width card that has image styles, blocks, text styles, and a list group are displayed.
<div class="card" styles="width: 18rem;"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p></div><ul class="list-group list-group-flush"><li class="list-group-item">An item</li><li class="list-group-item">A second item</li><li class="list-group-item">A third item</li></ul><div class="card-body"><a href="#" class="card-link">Card link</a><a href="#" class="card-link">Another link</a></div></div>
RESULT
Card title
Some quick example text to build on the card title and make up the bulk of the card's content.
- An item
- A second item
- A third item
Header and footer #
Add an optional header and/or footer within a card.
<div class="card"><div class="card-header">Featured</div><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div>
RESULT
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereCard headers can be styled by adding .card-header to
<h*>
elements.
<div class="card"><h5 class="card-header">Featured</h5><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div>
RESULT
Featured
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhere<div class="card"><div class="card-header">Quote</div><div class="card-body"><blockquote class="blockquote mb-0"><p>A well-known quote, contained in a blockquote element.</p><footer class="blockquote-footer">Someone famous in <cite title="Source Title">Source Title</cite></footer></blockquote></div></div>
RESULT
A well-known quote, contained in a blockquote element.
<div class="card text-center"><div class="card-header">Featured</div><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div><div class="card-footer text-muted">2 days ago</div></div>
RESULT
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereSizing #
In the absence of a precise width assumption at the outset, cards will always be 100%
wide. With custom CSS, grid classes, grid Sass mixins, or utilities, it can be modified as necessary.
Using grid markup #
Using the grid, wrap cards in columns and rows as needed.
<div class="row"><div class="col-sm-6"><div class="card"><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div></div><div class="col-sm-6"><div class="card"><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div></div></div>
RESULT
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereSpecial title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereUsing utilities #
Use our handful of available sizing utilities to quickly set a card’s width.
<div class="card w-75">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Button</a>
</div>
</div>
<div class="card w-50">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Button</a>
</div>
</div>
RESULT
Using custom CSS #
Use custom CSS in your stylesheets or as inline styles to set a width.
<div class="card" styles="width: 18rem;"><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div>
RESULT
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereText alignment #
You can quickly change the text alignment of any card—in its entirety or specific parts—with our text align classes.
<div class="card" styles="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
<div class="card text-center" styles="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
<div class="card text-end" styles="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
RESULT
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereSpecial title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereSpecial title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereNavigation #
Add some navigation to a card’s header (or block) with UX4G’s nav components.
<div class="card text-center"><div class="card-header"><ul class="nav nav-tabs card-header-tabs"><li class="nav-item"><a class="nav-link active" aria-current="true" href="#">Active</a></li><li class="nav-item"><a class="nav-link" href="#">Link</a></li><li class="nav-item"><a class="nav-link disabled">Disabled</a></li></ul></div><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div>
RESULT
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhere<div class="card text-center"><div class="card-header"><ul class="nav nav-pills card-header-pills"><li class="nav-item"><a class="nav-link active" href="#">Active</a></li><li class="nav-item"><a class="nav-link" href="#">Link</a></li><li class="nav-item"><a class="nav-link disabled">Disabled</a></li></ul></div><div class="card-body"><h5 class="card-title">Special title treatment</h5><p class="card-text">With supporting text below as a natural lead-in to additional content.</p><a href="#" class="btn btn-primary">Go somewhere</a></div></div>
RESULT
Special title treatment
With supporting text below as a natural lead-in to additional content.
Go somewhereImages #
A few options exist for manipulating the graphics on cards. It is possible to add "image caps"
to the ends of cards, place pictures over the data on the cards, or just embed pictures right into the cards themselves.
Image caps #
Cards can have top and bottom "image caps"
—images at the top or bottom of a card —much like headers and footers can.
<div class="card mb-3">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
<img src="..." class="card-img-bottom" alt="..."/>
</div>
RESULT
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Last updated 3 mins ago
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Last updated 3 mins ago
Image overlays #
Create a card background out of an image, then add text on top. There might or might not need additional styles or utilities, depending on the image.
<div class="card text-bg-dark">
<img src="..." class="card-img" alt="..."/>
<div class="card-img-overlay">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class="card-text">Last updated 3 mins ago</p>
</div>
</div>
RESULT
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Last updated 3 mins ago
Card styles #
Cards include various options for customizing their backgrounds, borders, and color.
Background and color #
Added in v1.0.2
Using the .text-bg-{color}
tools, you may set a background color with a contrasting foreground color. Previously, pairing your preferred .text-{color}
and .bg-{color}
utilities manually was necessary for styling; nevertheless, it is still free to do so if it is a preference
<div class="card text-bg-primary mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Primary card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card text-bg-secondary mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Secondary card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card text-bg-success mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Success card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card text-bg-danger mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Danger card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card text-bg-warning mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Warning card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card text-bg-info mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Info card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card text-bg-light mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Light card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card text-bg-dark mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Dark card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
RESULT
Primary card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Secondary card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Success card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Danger card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Warning card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Info card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Light card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Dark card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Conveying meaning to assistive technologies ​
Color-coding to add meaning just gives a visual cue, which users of assistive technologies like screen readers won't be able to understand. Make sure the information color designates is either evident from the content itself (such as the visible text) or is included in another way, such as by hiding additional text using the .visually-hidden
class.
Border #
To alter a card's border color only, use border utils. A subset of the card's contents, as seen below, or the parent .card
can both have {.text-color}
classes applied to them.
<div class="card border-primary mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body text-primary">
<h5 class="card-title">Primary card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card border-secondary mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body text-secondary">
<h5 class="card-title">Secondary card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card border-success mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body text-success">
<h5 class="card-title">Success card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card border-danger mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body text-danger">
<h5 class="card-title">Danger card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card border-warning mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Warning card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card border-info mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Info card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card border-light mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Light card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<div class="card border-dark mb-3" styles="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body text-dark">
<h5 class="card-title">Dark card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
RESULT
Primary card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Secondary card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Success card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Danger card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Warning card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Info card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Light card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Dark card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Mixins utilities #
Additionally, adjust the card's header and footer's borders as desired and, using the .bg-transparent
style, even get rid of their background colors.
<div class="card border-success mb-3" styles="max-width: 18rem;"><div class="card-header bg-transparent border-success">Header</div><div class="card-body text-success"><h5 class="card-title">Success card title</h5><p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p></div><div class="card-footer bg-transparent border-success">Footer</div></div>
RESULT
Success card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Card layout #
UX4G offers a few options for organizing a sequence of cards in addition to decorating the content within cards. These layout choices are not yet responsive at this time.
Card groups #
To render cards as a single, associated element with columns of the same width and height, use card groups. Beginning at the sm breakpoint, card groups that are initially stacked use display: flex to attach and take on uniform proportions.
<div class="card-group"><div class="card"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p><p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p></div></div><div class="card"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p><p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p></div></div><div class="card"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p><p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p></div></div></div>
RESULT
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Last updated 3 mins ago
Card title
This card has supporting text below as a natural lead-in to additional content.
Last updated 3 mins ago
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
Last updated 3 mins ago
When using card groups with footers, their content will automatically line up.
<div class="card-group">
<div class="card">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
<div class="card">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
<div class="card">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
</div>
RESULT
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This card has supporting text below as a natural lead-in to additional content.
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
Grid cards #
Use the .row-cols classes of the UX4G grid system to modify how many grid
columns show per row (wrapped around your cards). For instance, this. From the medium breakpoint up, row-cols-1
arranges the cards in a single column, and .row-cols-md-2
divides four cards into equal rows of width.
<div class="row row-cols-1 row-cols-md-2 g-4">
<div class="col">
<div class="card">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<img src="..." class="card-img-top" alt="..."/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
</div>
RESULT
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Change it to .row-cols-3
and you’ll
see the fourth card wrap.
<div class="row row-cols-1 row-cols-md-3 g-4"><div class="col"><div class="card"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p></div></div></div><div class="col"><div class="card"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p></div></div></div><div class="col"><div class="card"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p></div></div></div><div class="col"><div class="card"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p></div></div></div></div>
RESULT
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
When you need equal height, add
.h-100
to the cards. If you want equal heights by
default, you can set $card-height: 100%
in Sass.
<div class="row row-cols-1 row-cols-md-3 g-4"><div class="col"><div class="card h-100"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p></div></div></div><div class="col"><div class="card h-100"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a short card.</p></div></div></div><div class="col"><div class="card h-100"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p></div></div></div><div class="col"><div class="card h-100"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p></div></div></div></div>
RESULT
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This is a short card.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content.
Card title
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Just like with card groups, card footers will automatically line up.
<div class="row row-cols-1 row-cols-md-3 g-4"><div class="col"><div class="card h-100"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p></div><div class="card-footer"><small class="text-muted">Last updated 3 mins ago</small></div></div></div><div class="col"><div class="card h-100"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p></div><div class="card-footer"><small class="text-muted">Last updated 3 mins ago</small></div></div></div><div class="col"><div class="card h-100"><img src="..." class="card-img-top" alt="..."/><div class="card-body"><h5 class="card-title">Card title</h5><p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p></div><div class="card-footer"><small class="text-muted">Last updated 3 mins ago</small></div></div></div></div>
RESULT
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This card has supporting text below as a natural lead-in to additional content.
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
Masonry #
To simulate the behavior of Masonry-like columns, there is an employment of CSS-only solution, but this technique had a lot of unfavorable side effects. Just use the Masonry plugin if there is a requirement to have this kind of layout. UX4G does not include masonry, but have created a demo example to get you going.
CSS #
Variables #
Added in v1.0.2Cards now leverage local CSS variables on.card for improved real-time customisation as part of UX4G's growing CSS variables approach. Sass is used to set the values for the CSS variables, therefore Sass customization is still available.
--#{$prefix}card-spacer-y: #{$card-spacer-y};
--#{$prefix}card-spacer-x: #{$card-spacer-x};
--#{$prefix}card-title-spacer-y: #{$card-title-spacer-y};
--#{$prefix}card-border-width: #{$card-border-width};
--#{$prefix}card-border-color: #{$card-border-color};
--#{$prefix}card-border-radius: #{$card-border-radius};
--#{$prefix}card-box-shadow: #{$card-box-shadow};
--#{$prefix}card-inner-border-radius: #{$card-inner-border-radius};
--#{$prefix}card-cap-padding-y: #{$card-cap-padding-y};
--#{$prefix}card-cap-padding-x: #{$card-cap-padding-x};
--#{$prefix}card-cap-bg: #{$card-cap-bg};
--#{$prefix}card-cap-color: #{$card-cap-color};
--#{$prefix}card-height: #{$card-height};
--#{$prefix}card-color: #{$card-color};
--#{$prefix}card-bg: #{$card-bg};
--#{$prefix}card-img-overlay-padding: #{$card-img-overlay-padding};
--#{$prefix}card-group-margin: #{$card-group-margin};
Sass variables #
$card-spacer-y: $spacer;
$card-spacer-x: $spacer;
$card-title-spacer-y: $spacer * .5;
$card-border-width: $border-width;
$card-border-color: var(--#{$prefix}border-color-translucent);
$card-border-radius: $border-radius;
$card-box-shadow: null;
$card-inner-border-radius: subtract($card-border-radius, $card-border-width);
$card-cap-padding-y: $card-spacer-y * .5;
$card-cap-padding-x: $card-spacer-x;
$card-cap-bg: rgba($black, .03);
$card-cap-color: null;
$card-height: null;
$card-color: null;
$card-bg: $white;
$card-img-overlay-padding: $spacer;
$card-group-margin: $grid-gutter-width * .5;