Skip to content

richardfrangie/playing-card

Repository files navigation

Playing Card

HTML CSS JavaScript Web Components

This project explores how to build a reusable playing-card with Web Components. It’s based on the Standard 52-Card Deck project, and focuses on component structure, styling, and layout techniques that can later be reused in a solitaire game.

docs/images/playing-cards.png

Demo

Live demo →

What it covers

  • Built wih HTML, CSS & JS
  • Uses Web Components (Custom Elements, Shadow DOM)
  • Responsive card layout
  • Flexbox and CSS Grid for layout
  • Positioning and stacking contexts

Installation/Setup

To use this component, copy the following files into your project:

fonts and images
playing-card/src/assets/*
component styles that can be changed
playing-card/src/css/PlayingCard.vars.css
component
playing-card/src/components/PlayingCard.js
├── assets/
│   └── (fonts and images)
├── css/
│   └── PlayingCard.vars.css
├── components/
│   └── PlayingCard.js
└── index.js

Then import the component in your JavaScript entry file:

import "./components/PlayingCard.js";

Usage

Use it like any other HTML element with the tag name playing-card. It accepts two attributes and one optional boolean attribute.

Attributes

  • suit: sets the type of card. Valid values are diamond, spade, heart, club
  • rank: sets the number of the card. Valid values range from 1 to 13
  • flipped: turns the card over. Boolean attribute

Example of use

<!-- Diamond ace -->
<playing-card suit="diamond" rank="1"></playing-card>

<!-- Flipped card -->
<playing-card suit="club" rank="13" flipped></playing-card>

Customizing the component

The file PlayingCard.vars.css contains CSS custom properties that control the component’s appearance. You can modify this file directly or override the variables in your own CSS.

playing-card {
--card-width: 200px;  /* fixed size */
/* or  */
--card-width: 10vw;   /* responsive size */
}

Status

  • Verified on Chromium and Firefox

References

About

Reusable playing-card component built with Web Components

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors