利用 `position: fixed` 與 `:hover` 偽類,零 JavaScript 即可打造右側固定浮動面板,支援圖示展開二維碼、工具提示等互動。
<div class="side-bar">
<a href="#" class="icon-qq">QQ 諮詢</a>
<a href="#" class="icon-wechat">
微信
<div class="wechat-tip">
<i class="arrow"></i>
<img src="wechat-qrcode.jpg" alt="微信訂閱號" width="138" height="138">
</div>
</a>
<a href="#" target="_blank" class="icon-weibo">微博</a>
<a href="mailto:contact@example.com" class="icon-mail">Email</a>
</div>
.side-bar {
position: fixed;
right: 25px;
bottom: 20px;
width: 66px;
z-index: 9999;
font-size: 0; line-height: 0; /* 消除 inline-block 間隙 */
}
.side-bar a {
display: inline-block;
width: 66px; height: 66px;
margin-bottom: 2px;
background: #ddd url(right_bg.png) no-repeat;
background-color: #ddd;
text-indent: -9999px; /* 隱藏文字 */
transition: background-color 0.3s;
}
.side-bar a:hover { background-color: #669fdd; }
/* 圖示定位 */
.icon-qq { background-position: 0 -62px; }
.icon-wechat { background-position: 0 -130px; position: relative; }
.icon-weibo { background-position: 0 -198px; }
.icon-mail { background-position: 0 -266px; }
/* 微信懸浮二維碼 */
.wechat-tip {
position: absolute;
right: 78px; top: -55px;
padding: 20px; border: 1px solid #d1d2d6;
background: #fff; display: none;
box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.icon-wechat:hover .wechat-tip { display: block; }
/* 三角箭頭 */
.wechat-tip .arrow {
position: absolute; right: -9px; top: 80px;
width: 9px; height: 16px;
background: url(right_bg.png) -88px -350px no-repeat;
}
這類浮動面板常用於客服入口、分享工具、回頂端按鈕,純 CSS 實作輕量且無阻塞,極適合效能敏感頁面。