Responsive Card using flex and grid
Published: 2022-10-18 20:26:37

**Flex**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qsbqadlh6lzxtdpw12st.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f12q01ux0xrkb694ycig.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g5biymp7qy510g9fgcue.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1u00viesx8pmuczxlw9p.PNG)

```html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flex Card 2</title>
    <link rel="stylesheet" href="flexCard2.css">
</head>

<body>
    <div class="container">
        <div class="card">
            <img src="images/coffee.jpg" alt="">
            <p>Lorem ipsum dolor sit amet consectetur.</p>
        </div>
        <div class="card">
            <img src="images/teaCup.PNG" alt="">
            <p>Lorem ipsum dolor sit amet consectetur.</p>
        </div>
        <div class="card">
            <img src="images/teaSun.jpg" alt="">
            <p>Lorem ipsum dolor sit amet consectetur.</p>
        </div>
        <div class="card">
            <img src="images/cold.PNG" alt="">
            <p>Lorem ipsum dolor sit amet consectetur.</p>
        </div>
        <div class="card">
            <img src="images/mileCoffee.PNG" alt="">
            <p>Lorem ipsum dolor sit amet consectetur.</p>
        </div>
    </div>
</body>

</html>
```


```css
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.container {
    display: flex;
    justify-content: center;
    align-items: center; 
    flex-wrap: wrap;   
}

.card {
    width: 250px;
    height: 300px;
    background: lightblue;
    margin: 20px;
    padding: 10px;
}

img {
    width: 100%;
    height: 70%;
}
```

---
---

**Grid**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8wxueqimo0hmsav2s1j.PNG)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xi4vk5pfz9et5yiayd9.PNG)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6dyg8cm0ct12v9683uv0.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekkb6hcn9coyb2fzpfqs.PNG)

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Grid Card 2</title>
    <link rel="stylesheet" href="gridCard2.css">
</head>
<body>
    <div class="container">
        <div class="card">
            <img src="images/coffee.jpg" alt="">
            <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Neque, eius.</p>
        </div>
        <div class="card">
            <img src="images/teaCup.PNG" alt="">
            <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Neque, eius.</p>
        </div>
        <div class="card">
            <img src="images/teaSun.jpg" alt="">
            <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Neque, eius.</p>
        </div>
        <div class="card">
            <img src="images/cold.PNG" alt="">
            <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Neque, eius.</p>
        </div>
         
    </div>
</body>
</html>
```

```css
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.container {
    width: 95%;
    margin: 0 auto;

    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr) );
    grid-gap: 20px;
}

.card {
    max-width: 100%;
    height: 300px;

    padding: 10px;
    border-radius: 5px;
    background: lightblue;
}

img {
    width: 100%;
    height: 70%;
}
```