一款採用藍色主題的垂直時間軸,適合任務排程、專案里程碑、文章歸檔等場景。無需 JavaScript,僅靠 CSS 完成結構佈局與懸停動畫。
語義化標籤:<time> 標記時間,<ul> 承載時間點列表,<div class="cbp_tmlabel"> 包裹內容區塊。
<ul class="cbp_tmtimeline">
<li>
<time class="cbp_tmtime" datetime="2013-04-10 18:30">
<span>4/10/13</span> <span>18:30</span>
</time>
<div class="cbp_tmicon cbp_tmicon-phone"></div>
<div class="cbp_tmlabel">
<h2>事件標題</h2>
<p>詳細描述內容...</p>
</div>
</li>
<!-- 更多 li 節點 -->
</ul>
.cbp_tmtimeline {
position: relative;
padding: 2em 0;
list-style: none;
}
.cbp_tmtimeline::before {
content: '';
position: absolute;
top: 0; bottom: 0;
left: 50%; margin-left: -2px;
width: 4px; background: #3498db; /* 主題色 */
}
.cbp_tmicon {
position: absolute;
left: 50%; margin-left: -20px;
width: 40px; height: 40px;
border-radius: 50%;
background: #fff;
border: 4px solid #3498db;
z-index: 1;
}
.cbp_tmicon-phone::before { content: "\e900"; /* 圖標字體 */ }
.cbp_tmlabel {
position: relative;
width: 45%;
padding: 1.5em;
border-radius: 4px;
background: #f8f9fa;
box-shadow: 0 2px 6px rgba(0,0,0,.1);
}
.cbp_tmtimeline li:nth-child(odd) .cbp_tmlabel { left: 0; }
.cbp_tmtimeline li:nth-child(even) .cbp_tmlabel { left: 55%; }
.cbp_tmlabel::before {
content: '';
position: absolute;
top: 1.5em;
width: 0; height: 0;
border: 10px solid transparent;
}
li:nth-child(odd) .cbp_tmlabel::before {
right: -20px; border-left-color: #f8f9fa;
}
li:nth-child(even) .cbp_tmlabel::before {
left: -20px; border-right-color: #f8f9fa;
}
@keyframes fadeSlideUp {
from { opacity: 0; transform: translateY(30px); }
to { opacity: 1; transform: translateY(0); }
}
.cbp_tmtimeline li {
animation: fadeSlideUp 0.6s ease-out backwards;
}
.cbp_tmtimeline li:nth-child(n) { animation-delay: calc(var(--i) * 0.1s); }
@media (max-width: 640px) {
.cbp_tmtimeline::before { left: 20px; }
.cbp_tmicon { left: 20px; margin-left: 0; }
.cbp_tmlabel {
width: calc(100% - 60px);
left: 60px !important;
}
.cbp_tmlabel::before { left: -20px !important; border-right-color: #f8f9fa !important; }
}
IntersectionObserver 實現滾動觸發動畫。本文提供核心邏輯,完整可運行代碼(含圖標字體、動畫細節)請參考原文附件或至 CodePen 搜尋 "Vertical Timeline CSS Only"。