I am using particles-js in a new React project to learn more about how it works. I have set all and managed to show it as a background while having the React logo in the middle of the page. The problem comes when the webpage is loaded in a small window and the particles are stretched. I think I am missing a CSS attribute or something but I can't figure it out.
Do you know what could be the error?
Really thank you!
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="homeContainer">
<div id="particles-js">
<div id="root"></div>
</div>
</div>
<!--particles functions-->
<script type="text/javascript" src="%PUBLIC_URL%/particles.js"></script>
<!--particles config-->
<script type="text/javascript" src="%PUBLIC_URL%/utilities.js"></script>
</body>
</html>
index.css:
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
#root {
z-index: 100;
margin: auto;
width: 100%;
height: 100%;
position: absolute;
}
canvas {
position : absolute;
width:100%;
height:100%;
z-index:-1;
}in m
Here some photos to see what is happening:
UPDATE 1: In case it can be due an error in App.css, here it is its code:
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}