why font is jiggling when at scale 5 animating to 1?: <!DOCTYPE html> <html> <head>…
- User
why font is jiggling when at scale 5 animating to 1?:
.background-container { animation: animate-background 10s ease-in-out infinite; }
@keyframes animate-background { 0% { transform: rotate(0) scale(5); } 100% { transform: rotate(0deg) scale(1); } } .background-icon-container { position: absolute; top: 1em; left: 0; height: 100%; width: 100%; display: flex; justify-content: center; align-items: center; }.background-icon { font-size: 20em; }
.background-text-container { position: relative; top: 50%; left: 49%; transform: translate(-50%, -50%); max-width: 90%; max-height: 90%; white-space: nowrap; text-align: center; background-color: rgba(55, 255, 55, 0); color: green; mix-blend-mode: multiply; }
.background-text-container::before { content: attr(data-text); color: #1B5E20; mix-blend-mode: exclusion; }
.background-text-container::after { content: attr(data-text); color: #C62828; mix-blend-mode: screen; }
.background-text { font-size: 2em; line-height: 1.1em; }
- Assistant
The font is jiggling because of the combination of scale and translate properties. When you scale the container from 5 to 1, the font size also reduces. But because it is also translated to -50%, -50%, the font gets repositioned and jiggles around. You can fix this by removing the translate property and using flexbox to center the text both horizontally and vertically. Alternatively, you can also use the transform-origin property to adjust the anchor point of the transformation.
- User
try
- Assistant
Here's an updated code snippet with the fix applied:
<!DOCTYPE html> <html> <head> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; } .background { position: relative; width: 2em; height: 2em; margin: 1em; } .background-container { animation: animate-background 10s ease-in-out infinite; } @keyframes animate-background { 0% { transform: rotate(0) scale(5); } 100% { transform: rotate(0deg) scale(1); } } .background-icon-container { position: absolute; top: 1em; left: 0; height: 100%; width: 100%; display: flex; justify-content: center; align-items: center; } .background-icon { font-size: 20em; } .background-text-container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; } .background-text-container::before { content: attr(data-text); color: #1B5E20; mix-blend-mode: exclusion; } .background-text-container::after { content: attr(data-text); color: #C62828; mix-blend-mode: screen; } .background-text { font-size: 2em; line-height: 1.1em; } </style> </head> <body> <div class="background-container"> <div class="background-icon-container"> <span class="background-icon">🇩🇪</span> </div> <div class="background-text-container"> <span class="background-text">YES, WE CARE!</span> </div> </div> </body> </html> - User
put all display: values
- Assistant
Sure, here's the updated CSS with all the
displayvalues:body { display: flex; justify-content: center; align-items: center; height: 100vh; } .background { position: relative; width: 2em; height: 2em; margin: 1em; } .background-container { animation: animate-background 10s ease-in-out infinite; display: flex; justify-content: center; align-items: center; } @keyframes animate-background { 0% { transform: rotate(0) scale(5); } 100% { transform: rotate(0deg) scale(1); } } .background-icon-container { position: absolute; top: 1em; left: 0; height: 100%; width: 100%; display: flex; justify-content: center; align-items: center; } .background-icon { font-size: 20em; } .background-text-container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 90%; max-height: 90%; white-space: nowrap; text-align: center; background-color: rgba(55, 255, 55, 0); color: green; mix-blend-mode: multiply; display: flex; justify-content: center; align-items: center; } .background-text-container::before { content: attr(data-text); color: #1B5E20; mix-blend-mode: exclusion; } .background-text-container::after { content: attr(data-text); color: #C62828; mix-blend-mode: screen; } .background-text { font-size: 2em; line-height: 1.1em; display: flex; justify-content: center; align-items: center; }