分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

CSS3实现带阴影的弹球

发布时间:2023-09-06 01:39责任编辑:胡小海关键词:CSS

实现div上下跳动时,底部阴影随着变化

<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title>CSS3实现带阴影的弹球</title> ???<style type="text/css"> ???????.box{ ???????????width: 400px; ???????????height: 300px; ???????????border: 1px #cccccc solid; ???????????/*距上下30,左右居中*/ ???????????margin: 30px auto; ???????????/* 设置相对定位,以便子元素使用绝对定位 */ ???????????position: relative; ???????} ???????.box .ball, .box .ball:after{ ???????????border-radius: 50%; ???????????position: absolute; ???????????left: 50%; ???????????background: linear-gradient(top, #ffffff, #999999); ???????????background: -webkit-linear-gradient(top, #ffffff, #999999); ???????????background: -moz-linear-gradient(top, #ffffff, #999999); ???????????background: -ms-linear-gradient(top, #ffffff, #999999); ???????????background: -o-linear-gradient(top, #ffffff, #999999); ???????} ???????.box .ball{ ???????????width: 140px; ???????????height: 140px; ???????????top: 0; ???????????/*因为是绝对定位,距左边百分之50,这里距左是左边距盒子左边,所以这里需要通过margin向左移动宽度一般的距离*/ ???????????margin-left: -70px; ???????????-webkit-box-shadow: inset 0 0 30px #999999,inset 0 -15px 70px #999999; ???????????-moz-box-shadow: inset 0 0 30px #999999,inset 0 -15px 70px #999999; ???????????box-shadow: inset 0 0 30px #999999,inset 0 -15px 70px #999999; ???????????-webkit-animation: jump 5s ease-in infinite; ???????????-o-animation: jump 5s ease-in infinite; ???????????animation: jump 5s ease-in infinite; ???????????/*让球遮住阴影(使球显示在阴影上方)*/ ???????????z-index: 1; ???????} ???????.box .ball:after{ ???????????content: ""; ???????????display: block; ???????????width: 70px; ???????????height: 30px; ???????????border-radius: 50%; ???????????top: 10px; ???????????margin-left: -35px; ???????} ???????.box .shadow{ ???????????width: 80px; ???????????height: 60px; ???????????border-radius: 50%; ???????????position: absolute; ???????????bottom: 0; ???????????left: 50%; ???????????margin-left: -40px; ???????????background: rgba(20, 20, 20, .1); ???????????-webkit-box-shadow: 0 0 25px 20px rgba(20, 20, 20, .1); ???????????-moz-box-shadow: 0 0 25px 20px rgba(20, 20, 20, .1); ???????????box-shadow: 0 0 25px 20px rgba(20, 20, 20, .1); ???????????-webkit-transform: scaleY(.3); ???????????-moz-transform: scaleY(.3); ???????????-ms-transform: scaleY(.3); ???????????-o-transform: scaleY(.3); ???????????transform: scaleY(.3); ???????????-webkit-animation: shrink 5s ease-in infinite; ???????????-o-animation: shrink 5s ease-in infinite; ???????????animation: shrink 5s ease-in infinite; ???????} ???????@-webkit-keyframes jump { ???????????0%{ top: 0; } ???????????65%{ top: 160px; height: 140px; } ???????????75%{ height: 120px; } ???????????100%{ top: 0; height: 140px; } ???????} ???????@-o-keyframes jump { ???????????0%{ top: 0; } ???????????65%{ top: 160px; height: 140px; } ???????????75%{ height: 120px; } ???????????100%{ top: 0; height: 140px; } ???????} ???????@keyframes jump { ???????????0%{ top: 0; } ???????????65%{ top: 160px; height: 140px; } ???????????75%{ height: 120px; } ???????????100%{ top: 0; height: 140px; } ???????} ???????@-webkit-keyframes shrink { ???????????0%{ width: 90px; height: 60px; } ???????????65%{ width: 10px; height: 5px; margin-left: -5px; background: rgba(20, 20,20, .3); ???????????????-webkit-box-shadow: 0 0 25px 20px rgba(20, 20, 20, .3); ???????????????-moz-box-shadow: 0 0 25px 20px rgba(20, 20, 20, .3); ???????????????box-shadow: 0 0 25px 20px rgba(20, 20, 20, .3); } ???????????100%{ width: 90px; height: 60px; background: rgba(20, 20,20, .1); ???????????????-webkit-box-shadow: 0 0 25px 20px rgba(20, 20, 20, .1); ???????????????-moz-box-shadow: 0 0 25px 20px rgba(20, 20, 20, .1); ???????????????box-shadow: 0 0 25px 20px rgba(20, 20, 20, .1); } ???????} ???</style></head><body><div class="box"> ???<div class="ball"></div> ???<div class="shadow"></div></div></body></html>

CSS3实现带阴影的弹球

原文地址:https://www.cnblogs.com/xiaobaizhiqian/p/8366500.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved