Zum Inhalt springen

2.5: Card-Komponente

Lösungsvorschlag

`Card.module.css

.card {
position: relative;
width: 300px;
height: 300px;
border-radius: 30px;
background-position: center;
background-size: cover;
overflow: hidden;
color: white;
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
&:before {
transition: 1s;
position: absolute;
content: " ";
background: linear-gradient(to right, #f9466d, #7257d5, #7257d5);
border-radius: 30px;
width: 325px;
height: 325px;
transform: translateY(55%) rotate(80deg);
}
&:hover:before {
transform: translateY(60%) rotate(90deg);
border-radius: 0;
}
:global(.content) {
display: grid;
grid-template-columns: 70px 1fr;
grid-template-rows: 80px;
position: relative;
margin-top: 50%;
z-index: 1;
padding: 20px;
div {
margin-top: 30px;
text-align: center;
}
span {
align-self: center;
}
}
:global(img) {
height: 50px;
width: auto;
background-color: red;
border-radius: 10px;
box-shadow: 4px 4px 12px #00000099;
}
:global(a) {
justify-self: flex-end;
align-self: center;
color: #FFF;
border: 1px solid #FFF;
padding: 5px 7px;
&:hover {
background-color: #FFFFFF33;
}
}
}

Card.tsx

import { PropsWithChildren } from "react";
import styles from "./Card.module.css";
type CardProps = {
icon: string
cover: string;
date: string;
url: string;
text: string;
}
export function Card(props: PropsWithChildren<CardProps>) {
const {icon, cover, date, url, text, children} = props;
return (
<div className={styles.card} style={{backgroundImage: `url(${cover})`}}>
<div className="content">
<img src={icon} />
<div>
{children}
</div>
<span>
{date}
</span>
<a href={url}>{text}</a>
</div>
</div>
)
}

App.tsx

import cover from './cat.jpg'
import icon from './icon.png'
import './App.css'
import { Card } from './Card'
function App() {
return (
<>
<Card icon={icon} cover={cover} date="2025/04/15" text="Download now" url="https://axa.ch">
Fantastic price value!
</Card>
</>
)
}