PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 23, 2022

[FIXED] How to grid MDBootstrap cards in one row?

 July 23, 2022     bootstrap-4, mdbootstrap, reactjs     No comments   

Issue

I've used MDBootstrap cards in my React project.I'am finding difficult aligning in one row. Aligning 3 cards is what expected,but, the cards are stuck in vertical position only. See the code below for reference.

<MDBContainer>
      <MDBRow >      
      <MDBCol >
      <MDBCard style={{ width: "18rem", borderRadius:'10px'}} >
      { 
        data.map((data, index) => {
          return <div key={index}>
          <MDBCardImage className="img-fluid" src={data.img}
          waves style={{borderRadius:'10px'}} 
          style={{height:'350px', width:'310px'}} />
          <MDBCardBody>
            <MDBCardTitle style={{color:'black'}}>{data.title}</MDBCardTitle>
            <hr/>
            <MDBCardText>
            {data.content}
            </MDBCardText>
            <MDBBtn href="#">Github</MDBBtn>
            <MDBBtn href="#">Live Demo</MDBBtn>
          </MDBCardBody>
          <br/>
          </div> 
        })
      }  
      </MDBCard>
    </MDBCol>
  </MDBRow>
</MDBContainer>

Below is the image. This is what the end result I'am getting. Any solution?

enter image description here


Solution

You only have 1 column inside row and iterating data inside column only which results in single column stacked format. Your iteration should return separate columns like:

<MDBRow>
    {
    data.map((data, index) => {
    return <MDBCol key={index}>
        <MDBCard style={{ width: "18rem", borderRadius:'10px'}}>
            <MDBCardImage className="img-fluid" src={data.img} waves style={{borderRadius:'10px'}} style={{height:'350px', width:'310px'}} />
            <MDBCardBody>
                <MDBCardTitle style={{color:'black'}}>{data.title}</MDBCardTitle>
                <hr />
                <MDBCardText>
                    {data.content}
                </MDBCardText>
                <MDBBtn href="#">Github</MDBBtn>
                <MDBBtn href="#">Live Demo</MDBBtn>
            </MDBCardBody>
        </MDBCard>
    </MDBCol>
    })
    }
</MDBRow>


Answered By - ravibagul91
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing