本教程展示如何僅用 CSS3 創建乾淨的幻燈片面板:利用背景圖片分割切片,配合 Radio 按鈕與標籤實現點擊切換動畫,零 JavaScript 依賴。

在線演示效果
.cr-container input { display: none; }
.cr-container label {
width: 150px; height: 30px; cursor: pointer;
position: relative; margin-top: 350px; z-index: 1000; float: left;
}
.cr-container label:before { /* 圓形指示器 */
content: ''; width: 34px; height: 34px;
background: rgba(130,195,217,0.9); border-radius: 50%;
position: absolute; left: 50%; margin-left: -17px;
box-shadow: 0 0 0 4px rgba(255,255,255,0.3); z-index: -1;
}
.cr-container label:after {
content: ''; width: 1px; height: 400px;
background: linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%);
position: absolute; bottom: -20px; right: 0;
}
.cr-container label.cr-label-img-4:after { width: 0; } /* 最後一個無分割線 */
利用 `:checked ~` 選擇器,根據被選中的 radio 控制對應 label 樣式(顏色、背景、陰影)、背景圖片容器 `.cr-bgimg` 的背景圖、標題區塊顯示。
.cr-container input.cr-selector-img-1:checked ~ label.cr-label-img-1 { color: #68abc2; }
.cr-container input.cr-selector-img-1:checked ~ label.cr-label-img-1:before { background: #fff; box-shadow: 0 0 0 4px rgba(104,171,194,0.6); }
.cr-container input.cr-selector-img-1:checked ~ .cr-bgimg,
.cr-bgimg div span:nth-child(1) { background-image: url(../images/1.jpg); }
/* 同理處理 2/3/4 */
每個面板寬 150px(600/4),`overflow:hidden` 隱藏溢出。內部 `span` 初始 `left: -150px` 隱藏,選中時通過 CSS 動畫滑入可視區,形成切片拼合動畫。