时间轴(Timeline)是一种用于展示事件顺序和持续时间的可视化工具。在前端开发中,时间轴通常通过CSS和HTML来实现,用于展示历史事件、项目进度、时间线等。
以下是一个简单的水平时间轴的HTML和CSS示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timeline Example</title>
<style>
.timeline {
position: relative;
max-width: 1200px;
margin: 0 auto;
}
.timeline::after {
content: '';
position: absolute;
width: 6px;
background-color: #f2f2f2;
top: 0;
bottom: 0;
left: 50%;
margin-left: -3px;
}
.timeline-item {
position: relative;
min-height: 50px;
margin-bottom: 50px;
}
.timeline-item::before {
content: '';
position: absolute;
top: 25px;
left: 50%;
width: 20px;
height: 20px;
background-color: #f2f2f2;
border-radius: 50%;
margin-left: -10px;
}
.timeline-content {
padding: 20px;
background-color: #f9f9f9;
border-radius: 6px;
position: relative;
}
.timeline-content::before {
content: '';
position: absolute;
top: 25px;
right: 100%;
border-top: 10px solid transparent;
border-right: 10px solid #f9f9f9;
border-bottom: 10px solid transparent;
}
</style>
</head>
<body>
<div class="timeline">
<div class="timeline-item">
<div class="timeline-content">
<h3>Event 1</h3>
<p>Description of Event 1</p>
</div>
</div>
<div class="timeline-item">
<div class="timeline-content">
<h3>Event 2</h3>
<p>Description of Event 2</p>
</div>
</div>
<div class="timeline-item">
<div class="timeline-content">
<h3>Event 3</h3>
<p>Description of Event 3</p>
</div>
</div>
</div>
</body>
</html>CSS-Tricks: How to Create a Simple Timeline
.timeline::after和.timeline-item::before的定位和间距设置,确保它们正确对齐。margin或padding设置不当。.timeline-item和.timeline-content的margin和padding值,确保它们之间有足够的空间。通过以上方法,可以有效地解决时间轴在CSS实现中常见的问题。
没有搜到相关的沙龙