HTML+CSS实现时间轴效果
以下是一个简单的HTML和CSS代码示例,用于实现时间轴效果:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>时间轴示例</title>
<style>
body {
font-family: Arial, sans-serif;
}
.timeline {
list-style-type: none;
padding: 0;
position: relative;
}
.timeline-item {
position: relative;
margin-bottom: 20px;
}
.timeline-item-content {
background: #f9f9f9;
padding: 15px;
border-radius: 5px;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
}
.timeline-item-year {
position: absolute;
left: 50%;
transform: translateX(-50%);
color: #17a2b8;
top: -20px;
font-weight: 600;
font-size: 16px;
}
.timeline-item-circle {
position: absolute;
left: 50%;
transform: translateX(-50%);
background: #17a2b8;
width: 16px;
height: 16px;
border-radius: 50%;
top: 0;
z-index: 1;
}
.timeline-item-circle::after {
content: '';
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 12px;
height: 12px;
background: #f9f9f9;
border-radius: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.timeline-item-line {
position: absolute;
width: 100%;
height: 100%;
z-index: 0;
top: 16px; /* Account for the height of the circle */
left: 50%;
transform: translateX(-50%);
}
.timeline-item-line::before {
content: '';
position: absolute;
width: 2px;
height: 100%;
background: #17a2b8;
left: 50%;
top: 0;
transform: translateX(-50%);
}
</style>
</head>
<body>
<ul class="timeline">
<li class="timeline-item">
<div class="timeline-item-circle"></div>
<div class="timeline-item-line"></div>
<div class="timeline-item-content">
<span class="timeline-item-year">2023</span>
<p>开始学习编程。</p>
</div>
</li>
<li class="timeline-item">
<div class="timeline-item-circle"></div>
<div class="timeline-item-line"></div>
<div class="timeline-item-content">
<span class="timel
评论已关闭