How to make Cards Component Responsive and inside Cards is align Center

Viewed 40

I have some problems with my Cards component. I try to make 5 cards and it works but somehow the size doesn't follow the other cards and the card content is not centered and the text somehow got copied.

It should be like all card sizes are not affected by the size of the word and the title should be one and middle only.

import styled from 'styled-components';


const Cards = styled.div`
    padding: 4rem;
    background: #fff;
`

const CardsContainer = styled.div`
    display: flex;
    flex-flow: column;
    align-items: center;
    width: 90%;
    max-width: 1120px;
    margin: 0 auto;
`

const Title = styled.h1`
    text-align: center;
`

const CardsWrapper = styled.div`
    display: flex;
    flex-flow: column;
    width: 100%;
    margin-top: 20px;
    box-shadow: 0 6px 20px rgba(56, 125, 255, 0.17);
    -webkit-filter: drop-shadow(0 6px 20px rgba(56, 125, 255, 0.017));
    filter: drop-shadow(0 6px 20px rgba(56, 125, 255, 0.017));
    border-radius: 10px;
    overflow: hidden;
    text-decoration: none;
`

const CardItems = styled.ul`
    display: flex;
    flex-direction: column;
    margin-bottom: 24px;
`

const Image = styled.img`
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 50%;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    color: white;
    background-color: #80808044;
`

const Info = styled.div`
    text-align: center;
    padding: 20px 30px 30px;
`

const InfoText = styled.h3`
    color: #252e48;
    margin-bottom: 10px;
`

const SubText = styled.p`
    color: #252e489c;
    font-size: 14px;
    line-height: 24px;
`

function InfoCardItem({services}) {
    return (
        <Cards>
            <CardsContainer>
                <Title>Apa yang sobat cari?</Title>
                <CardsWrapper>
                    <CardItems>
                            <Image src={services.img} />
                            <Info>
                                <InfoText>{services.text}</InfoText>
                                <SubText>{services.sub}</SubText>
                            </Info>
                    </CardItems>
                </CardsWrapper>
            </CardsContainer>
        </Cards>
    );
}

export default InfoCardItem;

import styled from "styled-components";
import { services } from "../data"
import InfoCardItem from "./InfoCardItem"

const CardsItem = styled.li`
    display: flex;
    flex: 1;
    margin: 0 1rem;
    border-radius: 10px;
`

function InfoCard() {
  return (
    <CardsItem>
      {services.map(services=>(
        <InfoCardItem services={services} key={services.id}/>
      ))}
    </CardsItem>
  );
}

export default InfoCard;

So the top code error result should be this Result

Is there any fix for this problem to make it center content, 1 title only and responsive with mobile?

1 Answers

Maybe this will help you and sorry i did not use react

.row {
  margin: 0 -5px;
}

.row:after {
  content: "";
  display: table;
  clear: both;
}

.col {
  float: left;
  width: 25%;
  padding: 0 10px;
  display: flex;
  align-items: center;
  flex-direction: column;
}

.card {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
  width: 60%;
  border-radius: 5px;
}

.card:hover {
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}

img {
  border-radius: 5px 5px 0 0;
}

.container {
  padding: 2px 16px;
  display: flex;
  align-items: center;
  flex-direction: column;
}
<html>
  <div class="row">
    <div class="col">
      <p>
        title
      </p>
      <div class="card">
        <img src="https://www.pngall.com/wp-content/uploads/5/Profile-Avatar-PNG.png" alt="Avatar" style="width:100%">
        <div class="container">
          <h4><b>Jane Doe</b></h4>
          <br />
          <p>Interior Designer</p>
        </div>
      </div>
    </div>

    <div class="col">
      <p>
        title
      </p>
      <div class="card">
        <img src="https://www.pngall.com/wp-content/uploads/5/Profile-Avatar-PNG.png" alt="Avatar" style="width:100%">
        <div class="container">
          <h4><b>Jane Doe</b></h4>
          <br />
          <p>Interior Designer</p>
        </div>
      </div>
    </div>

    <div class="col">
      <p>
        title
      </p>
      <div class="card">
        <img src="https://www.pngall.com/wp-content/uploads/5/Profile-Avatar-PNG.png" alt="Avatar" style="width:100%">
        <div class="container">
          <h4><b>Jane Doe</b></h4>
          <br />
          <p>Interior Designer</p>
        </div>
      </div>
    </div>
  </div>

</html>

Related