如何創建:固定的社交欄
學習如何使用 CSS 創建固定/粘性社交媒體圖標欄。
如何創建固定的社交欄
第一步 - 添加 HTML:
<!-- 加載 Font Awesome 圖標 --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <!-- 社交媒體圖標欄 --> <div class="icon-bar"> <a href="#" class="facebook"><i class="fa fa-facebook"></i></a> <a href="#" class="twitter"><i class="fa fa-twitter"></i></a> <a href="#" class="google"><i class="fa fa-google"></i></a> <a href="#" class="linkedin"><i class="fa fa-linkedin"></i></a> <a href="#" class="youtube"><i class="fa fa-youtube"></i></a> </div>
第二步 - 添加 CSS:
/* 固定/粘性圖標欄(垂直對齊于屏幕頂部50%的位置) */ .icon-bar { position: fixed; top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); } /* 設置圖標欄鏈接的樣式 */ .icon-bar a { display: block; text-align: center; padding: 16px; transition: all 0.3s ease; color: white; font-size: 20px; } /* 如果需要,為社交媒體圖標設置顏色樣式 */ .icon-bar a:hover { background-color: #000; } .facebook { background: #3B5998; color: white; } .twitter { background: #55ACEE; color: white; } .google { background: #dd4b39; color: white; } .linkedin { background: #007bb5; color: white; } .youtube { background: #bb0000; color: white; }
相關頁面
教程:CSS 定位