I made a little square box rotating on itself next to a little text. And i positionate it accordingly to what i'm looking for, but sadly, when i play with the screen dimension for testing responsivity of the website, the square is moving too much.
I usually only do responsive by media queries, but this time, since the square is moving at every pixel, it would take A LOT of media queries to make it look fixed to the text.
Theres is any better way to make this animation responsive than spamming media queries to change his position?
here's the HTML code :
<!-- Carré jaune animé -->
<div class="rotating-square"></div>
here's the CSS code :
.rotating-square {
position: absolute;
bottom: -270%; /* Ajuster la position verticale */
right: 15%;
transform: translateX(50%);
width: 150px; /* Ajuster la taille du carré */
height: 150px; /* Ajuster la taille du carré */
background-color: rgb(17, 0, 255);
z-index: -1; /* Mettre le carré derrière le contenu pour ne pas affecter la lisibilité du texte */
animation: rotateSquare 8s linear infinite; /* Appliquer l'animation */
}
/* Animation pour faire tourner le carré */
@keyframes rotateSquare {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
on little screen on bigger screen (and closer to what i'm looking for)
I want to learn better way (more efficient, less time consuming) than media queries for make something responsive
i found this wich was pretty usefull : How to make a position absolute css animation responsive?
But since in my case it's already a single thing (.rotating-square) to move, it's still dont really change what i'm looking for.
EDIT : Here's the playground ! : https://codepen.io/Kurio-the-scripter/pen/qBLEemo
At my full screen (1980x1080) the green box is between the two colored text. But if you play with the scale of the windows, you will see the box moving though the page, getting over the text, i want to avoid it that and keep it his first place. (beetween the text)
EDIT 2 : Even if the situation and solution wasn't the same, the edit about using margin instead other things to center an object for responsivity worked like a charm !
Thanks !