Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My problem is when I resize the screen to make the screen smaller my divs begin to overlap after a certain point. However, the behavior that I would like to have is when there is not enough space for multiple divs in a row, then the divs must go under each other and fit the screen. I would like to maintain my grid gap when resizing.

What I have tried:

JavaScript
const gridTexts = [
      "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
      "orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset",
      "orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's."
    ];

    const rootElement = document.getElementById("root");

    ReactDOM.render(
       <div className ="App">
        <div className = "grid-container" > 
          {gridTexts.map((gridText) => ( 
            <div className = "card">
              <span> {gridText} </span> 
            </div>
          ))}
        </div>
       </div>,
      rootElement
    );


CSS
.App {
      font-family: sans-serif;
      text-align: center;
    }

    .grid-container {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
      grid-template-rows: 1fr;
      grid-column-gap: 30px;
      grid-row-gap: 30px;
      margin-top: 50px;
    }

    .card {
      padding: 30px;
      height: 90%;
      background-color: aqua;
      min-width: 200px;
    }

HTML
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="theme-color" content="#000000">
  <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
  <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
  <title>React App</title>
</head>

<body>
  <noscript>
		You need to enable JavaScript to run this app.
	</noscript>
  <div id="root"></div>
</body>

</html>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900