css制作红色小球
使用CSS制作红色小球
通过CSS的border-radius属性和background-color属性可以轻松创建一个红色小球。
.red-ball {
width: 50px;
height: 50px;
background-color: red;
border-radius: 50%;
}
添加动画效果
如果需要让红色小球具有动画效果,可以使用CSS的animation属性。
.red-ball {
width: 50px;
height: 50px;
background-color: red;
border-radius: 50%;
animation: bounce 2s infinite;
}
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-20px);
}
}
使用伪元素创建小球
也可以通过伪元素来生成红色小球,减少HTML中的DOM节点。
.container::before {
content: '';
display: block;
width: 50px;
height: 50px;
background-color: red;
border-radius: 50%;
}
响应式小球
为了使小球在不同屏幕尺寸下保持比例,可以使用vw或vh单位。
.red-ball {
width: 10vw;
height: 10vw;
background-color: red;
border-radius: 50%;
}
添加阴影效果
通过box-shadow属性可以为小球增加立体感。
.red-ball {
width: 50px;
height: 50px;
background-color: red;
border-radius: 50%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}




