父块中有一个球:
body {
background: black;
}
.box {
position: relative;
overflow: hidden;
margin: 0 auto;
width: 500px;
height: 300px;
border-radius: 5px;
box-shadow: inset 0 0 2px black;
background-color: white;
}
.ball {
position: absolute;
width: 20px;
height: 20px;
border-radius: 100%;
background-color: black;
box-shadow: inset -5px -5px 5px rgba(0, 0, 0, .5), 15px 15px 2px rgba(0, 0, 0, .05);
}
<div class="box">
<div class="ball"></div>
</div>
我怎样才能让它无限期地移动并从这个块的边界边缘反弹?
嗯...为什么不在 CSS 中做呢?只需添加两行动画:
为什么不在 SVG 中做呢?