|
| 1 | +# Card Layout |
| 2 | + |
| 3 | +A three-card layout component for displaying featured content with images, titles, descriptions, and links. |
| 4 | + |
| 5 | +[View Demo](demo_card-layout.html) |
| 6 | + |
| 7 | +## Key Features |
| 8 | + |
| 9 | +- **Fixed Three-Card Layout**: Displays exactly three cards in a responsive flexbox row |
| 10 | +- **Attribute-Based Content**: Configure each card via simple HTML attributes |
| 11 | +- **Responsive Design**: Cards stack automatically on smaller screens |
| 12 | +- **Encapsulated Styles**: Shadow DOM prevents style conflicts with your page |
| 13 | +- **Automatic Updates**: Once installed, the component receives updates when new versions are released |
| 14 | + |
| 15 | +## Installing |
| 16 | + |
| 17 | +```html |
| 18 | +<!-- Add the component --> |
| 19 | +<card-layout |
| 20 | + card1-title="Card One" |
| 21 | + card1-description="Your description here." |
| 22 | + card1-link="/page1" |
| 23 | + |
| 24 | + card2-title="Card Two" |
| 25 | + card2-description="Another description." |
| 26 | + card2-link="/page2" |
| 27 | + |
| 28 | + card3-title="Card Three" |
| 29 | + card3-description="Third description." |
| 30 | + card3-link="/page3" |
| 31 | +></card-layout> |
| 32 | + |
| 33 | +<!-- Include the JavaScript --> |
| 34 | +<script type="module" src="https://media.library.caltech.edu/cl-webcomponents/card-layout.js"></script> |
| 35 | +``` |
| 36 | + |
| 37 | +## Basic Usage |
| 38 | + |
| 39 | +At minimum, provide a title and description for each card: |
| 40 | + |
| 41 | +```html |
| 42 | +<card-layout |
| 43 | + card1-title="Sherman Fairchild Library" |
| 44 | + card1-description="Study spaces, course reserves, and technology lending." |
| 45 | + card1-link="https://library.caltech.edu/locations/sfl" |
| 46 | + |
| 47 | + card2-title="Caltech Archives" |
| 48 | + card2-description="Explore Caltech's rich history and scientific legacy." |
| 49 | + card2-link="https://library.caltech.edu/archives" |
| 50 | + |
| 51 | + card3-title="Research Support" |
| 52 | + card3-description="Get help with data management, publishing, and more." |
| 53 | + card3-link="https://library.caltech.edu/publish" |
| 54 | +></card-layout> |
| 55 | +``` |
| 56 | + |
| 57 | +When no image is provided, a placeholder is displayed. |
| 58 | + |
| 59 | +## Adding Images |
| 60 | + |
| 61 | +Add images to each card using the `card[1-3]-image` attributes: |
| 62 | + |
| 63 | +```html |
| 64 | +<card-layout |
| 65 | + card1-image="https://example.com/image1.jpg" |
| 66 | + card1-title="Digital Collections" |
| 67 | + card1-description="Browse digitized rare books, photographs, and manuscripts." |
| 68 | + card1-link="https://library.caltech.edu/archives/collections" |
| 69 | + |
| 70 | + card2-image="https://example.com/image2.jpg" |
| 71 | + card2-title="Workshops & Events" |
| 72 | + card2-description="Join us for research skills workshops and special events." |
| 73 | + card2-link="https://library.caltech.edu/events" |
| 74 | + |
| 75 | + card3-image="https://example.com/image3.jpg" |
| 76 | + card3-title="Course Reserves" |
| 77 | + card3-description="Access textbooks and materials for your courses." |
| 78 | + card3-link="https://library.caltech.edu/borrow/reserves" |
| 79 | +></card-layout> |
| 80 | +``` |
| 81 | + |
| 82 | +## Custom Link Text |
| 83 | + |
| 84 | +By default, links display "Read more". Customize with `card[1-3]-link-text`: |
| 85 | + |
| 86 | +```html |
| 87 | +<card-layout |
| 88 | + card1-title="Digital Collections" |
| 89 | + card1-description="Browse our digitized materials." |
| 90 | + card1-link="https://library.caltech.edu/archives/collections" |
| 91 | + card1-link-text="Explore collections" |
| 92 | + |
| 93 | + card2-title="Workshops & Events" |
| 94 | + card2-description="Join us for upcoming events." |
| 95 | + card2-link="https://library.caltech.edu/events" |
| 96 | + card2-link-text="View calendar" |
| 97 | + |
| 98 | + card3-title="Course Reserves" |
| 99 | + card3-description="Access course materials." |
| 100 | + card3-link="https://library.caltech.edu/borrow/reserves" |
| 101 | + card3-link-text="Find reserves" |
| 102 | +></card-layout> |
| 103 | +``` |
| 104 | + |
| 105 | +## Hiding Links |
| 106 | + |
| 107 | +If you don't provide a `card[1-3]-link` attribute, the link will be hidden for that card: |
| 108 | + |
| 109 | +```html |
| 110 | +<card-layout |
| 111 | + card1-title="Information Only" |
| 112 | + card1-description="This card has no link." |
| 113 | + |
| 114 | + card2-title="With Link" |
| 115 | + card2-description="This card has a link." |
| 116 | + card2-link="/some-page" |
| 117 | + |
| 118 | + card3-title="Also No Link" |
| 119 | + card3-description="Another card without a link." |
| 120 | +></card-layout> |
| 121 | +``` |
| 122 | + |
| 123 | +## Complete Example |
| 124 | + |
| 125 | +Here's a fully configured card layout using all available options: |
| 126 | + |
| 127 | +```html |
| 128 | +<card-layout |
| 129 | + card1-image="https://example.com/collections.jpg" |
| 130 | + card1-title="Digital Collections" |
| 131 | + card1-description="Browse digitized rare books, photographs, and manuscripts from Caltech's history." |
| 132 | + card1-link="https://library.caltech.edu/archives/collections" |
| 133 | + card1-link-text="Explore collections" |
| 134 | + |
| 135 | + card2-image="https://example.com/events.jpg" |
| 136 | + card2-title="Workshops & Events" |
| 137 | + card2-description="Join us for research skills workshops, author talks, and special events." |
| 138 | + card2-link="https://library.caltech.edu/events" |
| 139 | + card2-link-text="View calendar" |
| 140 | + |
| 141 | + card3-image="https://example.com/reserves.jpg" |
| 142 | + card3-title="Course Reserves" |
| 143 | + card3-description="Access textbooks, readings, and other materials for your courses." |
| 144 | + card3-link="https://library.caltech.edu/borrow/reserves" |
| 145 | + card3-link-text="Find reserves" |
| 146 | +></card-layout> |
| 147 | +``` |
| 148 | + |
| 149 | +## Attribute Reference |
| 150 | + |
| 151 | +| Attribute | Description | Default | |
| 152 | +|-----------|-------------|---------| |
| 153 | +| `card[1-3]-image` | URL for the card image | Placeholder shown | |
| 154 | +| `card[1-3]-title` | Card heading text | "Card One/Two/Three" | |
| 155 | +| `card[1-3]-description` | Brief description text | "Add your content here." | |
| 156 | +| `card[1-3]-link` | URL for the link | Link hidden if not set | |
| 157 | +| `card[1-3]-link-text` | Custom text for the link | "Read more" | |
| 158 | + |
| 159 | +Replace `[1-3]` with the card number (1, 2, or 3). |
| 160 | + |
| 161 | +## Responsive Behavior |
| 162 | + |
| 163 | +- **Desktop**: Cards display in a horizontal row with equal widths |
| 164 | +- **Mobile** (< 600px): Cards stack vertically, each taking full width |
| 165 | + |
| 166 | +The component handles this automatically with no additional configuration needed. |
0 commit comments