2

I am learning React and trying to build single page portfolio . When I tried to list my projects using grid, the problem ocurred. Is there any grid property to solve this problem. I am tired of trying.

This is my jsx:

const Project = () => {
  return (
    <div className="p">
      <h1 className="p-heading">React Projects</h1>
      <div className="p-card-container">
        {Data.map((item) => {
          return (
            <div className="p-card">
              <img src={item.image} alt="" />
              <h2 className="p-title">{item.title}</h2>
              <div className="p-details">
                <div className="p-btns">
                  <a className="btn" href={item.demo_link} target="_blank">
                    Demo
                  </a>
                  <a className="btn" href={item.github_link} target="_blank">
                    Code
                  </a>
                </div>
              </div>
            </div>
          );
        })}
      </div>
    </div>
  );
};

this is my css:

.p {
  width: 100%;
  height: 100vh;
  padding-top: 2em;
  background-color: beige;
}
.p-heading {
  text-align: center;
}
.p-card-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  grid-gap: 2em;
  padding: 2em 5em;
  background-color: white;
}
.p-card {
  padding: 2.5rem;
  box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.1);
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.p-card img {
  width: 100%;
  border-radius: 1em;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 5px;
}
.p-btns {
  display: flex;
  justify-content: space-between;
}
.p-btns .btn {
  text-decoration: none;
  padding: 0.5rem 1rem;
  background-color: #59b256;
  color: white;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  border-radius: 8px;
  width: 100px;
}
.p-btns .btn:nth-last-child(1) {
  margin-left: 0.7rem;
}

Note: I have used autofit for grid-template-column. Is it the reason for overlapping upper component.

  • I believe i could not reproduce your problem: https://prnt.sc/ks_otuKb3AZc Seems fine to me, can you post a Prin Screen of the problem? – Paulo Fernando Aug 28 '22 at 20:20
  • Thank you Paulo. Here is the screenshot of problem: https://prnt.sc/CC0OUitrO5p7 – Nirajan Karki Aug 29 '22 at 13:40
  • It's strange, seems that we are not using the same code, I put longer titles and it continued working: https://prnt.sc/Sv-A17tKZHtZ, also in your print I dont see the "React Projects", but I see this text "HTML & CSS projects", this text is not in the code you provided – Paulo Fernando Aug 29 '22 at 13:53
  • Oh sorry, here is the correct one: https://prnt.sc/Zgix2LT1OwpA. Here 'React Project' component moves up and overlap another component 'Contact' in mobile view. – Nirajan Karki Aug 29 '22 at 17:26
  • As I imagined, the problem is not in the code that you posted. I would have to see everything working together, can you make an example here: https://codesandbox.io/s/new – Paulo Fernando Aug 29 '22 at 17:33
  • Yes, I have added two components: Project.js and ProjectHtml.js. And the problem is still there, ProjectHtml.js comp moves up and overlaps Project.js in mobile view. Here is the link: https://codesandbox.io/s/vibrant-blackwell-5z7hrd?file=/src/App.js&resolutionWidth=453&resolutionHeight=675 – Nirajan Karki Aug 30 '22 at 09:34
  • I believe it's missing things in your codesandbox. I don't see the overlay problem, and the ProjectHtml.js is empty: https://prnt.sc/rIUdh1Qg6gfd – Paulo Fernando Aug 30 '22 at 14:32
  • Please try this link: https://codesandbox.io/s/vibrant-blackwell-5z7hrd?file=/src/ProjectHtml.js&resolutionWidth=453&resolutionHeight=675 – Nirajan Karki Aug 30 '22 at 16:40
  • Got the same : https://prnt.sc/N5hw4S-AltQi When you access the link you see the overlaping problem? https://codesandbox.io/s/vibrant-blackwell-5z7hrd?file=/src/ProjectHtml.js&resolutionWidth=453&resolutionHeight=675 – Paulo Fernando Aug 30 '22 at 17:01
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/247689/discussion-between-paulo-fernando-and-nirajan-karki). – Paulo Fernando Aug 30 '22 at 17:01
  • ok, I am waiting you in chat. – Nirajan Karki Aug 30 '22 at 17:33

0 Answers0