Make parent div spin, but without the children's content

前端 未结 1 1350
北恋
北恋 2021-01-27 01:17

I want to keep the text inside of the children absolutely positioned in the spinning div. So that the text is in the middle all the time. I didn\'t come across a solution, but I

1条回答
  •  再見小時候
    2021-01-27 01:53

    I think that you shouldn't use parent/child relationship. Just let them be siblings inside a container (I kept the class names just for showing the difference):

    This is child

    CSS

    @-webkit-keyframes rotate {
      from{ -webkit-transform: rotate(0deg);   }
      to{   -webkit-transform: rotate(360deg); }
    }
    .parent {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        background: #000;
        position: relative;
        top: 25%;
        border: 10px dashed red;
        -webkit-animation: rotate 12s linear infinite;
    }
    
    .container{
        position: relative;
    }
    
    .child {
        position: absolute;
        top: 50px;
        left: 20px;
        color: #fff;
        -webkit-animation: none !important;
    }
    

    Here is an updated JSFiddle

    0 讨论(0)
提交回复
热议问题