鼠标滑过显示详情
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>鼠标滑过显示详情</title> <!-- IMPORT CSS --> <style> * { margin: 0; padding: 0; } .box { /* CSS3新盒子模型属性:控制 WIDTH / HEIGHT 是盒子最终的宽高 */ box-sizing: border-box; margin: 20px auto; width: 200px; height: 40px; line-height: 40px; text-align: center; border: 1px solid lightcoral; position: relative; } .box .detail { display: none; position: absolute; right: -1px; top: 38px; z-index: -1; box-sizing: border-box; width: 500px; height: 100px; line-height: 100px; text-align: center; border: 1px solid lightcoral; } .box:hover { border-bottom-color: #FFF; } .box:hover .detail { display: block; } /* 如果是点击实现显示,不需要基于 JS 也可以,可以基于 :target 实现手风琴效果 */ </style></head><body> <!-- 基于 CSS 实现,我们需要让详情区域是按钮的子元素 --> <div class="box"> <span>购物车</span> <div class="detail"> 购物车的相关信息 </div> </div></body></html>