css 关闭按钮实现
通过css的伪元素:before,:after以及transform: rotate(45deg);旋转来实现(支持IE9及其以上版本)
<div class="close"></div>
/*关闭图标*/ .close { position: absolute; right: -25px; top: -25px; width: 50px; height: 50px; background: silver; border-radius: 25px; box-shadow: 2px 2px 5px 0px black; cursor: pointer; } .close:hover { background: red; } .close:before { position: absolute; content: ''; width: 30px; height: 10px; background: white; transform: rotate(45deg); top: 20px; left: 10px; } .close:after{ content: ''; position: absolute; width: 30px; height: 10px; background: white; transform: rotate(-45deg); top: 20px; left: 10px; }
效果图:
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步