When rotating a element inside a div, or fullscreen, if you know the dimensions you can make it wide or tall enough to hide it by making the inner element bounds. With responsive web design, this seem to be a issue when height/width is too far off each other where the diagonal becomes too long.
Here is a example of an rotating background pattern that works in some aspects, but once it goes too tall or too wide it breaks and green background color bleeds: Codepen
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vh;
overflow: hidden;
background: green;
}
.pattern {
width: 200%;
height: 200%;
position: fixed;
top: -50%;
right: -50%;
background-image: conic-gradient( white 0deg 45deg, black 45deg 90deg, white 90deg 135deg, black 135deg 180deg, white 180deg 225deg, black 225deg 270deg, white 270deg 315deg, black 315deg 360deg);
animation: rotate 4s linear infinite;
}
@keyframes rotate {
0% {
transform: rotate(0);
}
0% {
transform: rotate(1turn);
}
}
<div class="pattern"></div>
3
Answers
See this solution, max takes the highest value of 100vh or 100vw, adds it to a variable and adds it to the width and height, I made some other changes to make it work as expected:
This stays responsive under normal conditions – if device isn’t narrow and super long. I have added
@media
for narrower width, otherwise I couldn’t get it to work better. I’m curious if there is a better solution to it!Hopefully it helps!
Your code can be simplified like below. All you need a big negative value with
inset