且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使父级div旋转,但不包含子级的内容

更新时间:2023-10-29 08:26:16

我认为您不应该使用父子关系.只是让它们成为容器中的兄弟姐妹(我保留类名只是为了显示区别):

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):

<div class="container">
    <div class="parent"></div>
    <div class="child">This is child</div>
</div>

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;
}

这是更新的 JSFiddle