* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 50px;
}
body,
html {
width: 100%;
height: 100%;
display: grid;
place-items: center;
background: black;
}
.maindiv {
width: 4rem;
height: 4rem;
border-radius: 50%;
background-color: pink;
position: relative;
}
.internalcircle {
width: 3.5rem;
height: 3.5rem;
background-color: black;
border-radius: 50%;
animation: introtate 2s linear infinite alternate;
position: absolute;
transform-origin: center;
transform: translate(-50% -50%);
}
@keyframes introtate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
i wanted the inner circle div to rotate 360 deg so as to make a loader effect but the inner circle is going out of the main div even though i used the position:relative to the main-div. what should i do
i wanted to make a css loader. i tried to make the inner div to rotate 360deg in such a way that it makes a loader effect. i tried experimenting with transform-origin but still it rotates out of the main-div
2
Answers
try using position:relative in .innercircle and adjust it fron the inspector
You don’t need to use
position
,display: grid
can layer the elements.Also, separate out the transforms
translate
,rotate
etc. which can now be used individually. However, withoutposition
,transform: translate
(or justtranslate
) is actually not required.