事星級評論列表是一個廣泛使用的組件,它能夠增強網站的交互性和用戶參與度。而CSS樣式也是影響事星級評論列表視覺效果的重要因素之一。下面我們將介紹幾種常用的事星級評論列表CSS樣式。
/* 1. 簡單樣式 */ .star-rating { font-size: 2rem; color: #fca903; } .star-rating::before { content: "★★★★★"; } .star-rating span { position: absolute; top: 0; left: 0; overflow: hidden; width: 0; } /* 2. 帶有動畫效果的樣式 */ .star-rating { font-size: 2rem; color: #fca903; cursor: pointer; } .star-rating::before { content: "★★★★★"; } .star-rating span { position: absolute; top: 0; left: 0; overflow: hidden; width: 0; transition: width 0.5s; } .star-rating:hover span { width: 100%; } /* 3. 帶有評分數提示的樣式 */ .star-rating { font-size: 2rem; color: #fca903; cursor: pointer; } .star-rating::before { content: "★★★★★"; } .star-rating >span { position: absolute; top: 0; left: 0; overflow: hidden; width: 0; transition: width 0.5s; } .star-rating:hover >span, .star-rating:hover ~ .rating { width: 100%; } .rating { margin-left: 1rem; font-size: 1rem; color: #333; display: inline-block; vertical-align: top; line-height: 2rem; transition: width 0.5s; } /* 4. 帶有動態評分數的樣式 */ .star-rating-container { position: relative; display: inline-block; } .star-rating { font-size: 2rem; color: #fca903; cursor: pointer; position: relative; z-index: 2; } .star-rating::before { content: "★★★★★"; } .star-rating >span { position: absolute; top: 0; left: 0; overflow: hidden; width: 0; transition: width 0.5s; z-index: 1; } .star-rating:hover >span, .star-rating:hover ~ .rating { width: 100%; } .rating { margin-left: 1rem; font-size: 1rem; color: #333; display: inline-block; vertical-align: top; line-height: 2rem; transition: width 0.5s; position: relative; z-index: 2; } .rating::after { content: attr(data-rating); position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); color: #fff; z-index: -1; transition: width 0.5s; } .rating:hover::after { width: 0; }