html - 水平时间线 css 实现
问题描述
我正在尝试实现水平时间线,但我被卡住了。我需要帮助来实现它!
body {
background-color: black;
}
.timeline {
white-space: nowrap;
overflow-x: hidden;
}
.timeline ol {
font-size: 0;
width: 100vw;
padding: 250px 0;
transition: all 1s;
}
.timeline ol li {
position: relative;
display: inline-block;
list-style-type: none;
width: 160px;
height: 3px;
background: #fff;
}
.timeline ol li:last-child {
width: 280px;
}
.timeline ol li:not(:first-child) {
margin-left: 14px;
}
.timeline ol li:not(:last-child)::after {
content: '';
position: absolute;
top: 50%;
left: calc(100% + 1px);
bottom: 0;
width: 12px;
height: 12px;
transform: translateY(-50%);
border-radius: 50%;
background: #F45B69;
}
.timeline ol li div {
position: absolute;
left: calc(100% + 7px);
width: 280px;
padding: 15px;
font-size: 1rem;
white-space: normal;
color: black;
background: white;
}
.timeline ol li div::before {
content: '';
position: absolute;
top: 100%;
left: 0;
width: 0;
height: 0;
border-style: solid;
}
.timeline ol li:nth-child(odd) div {
top: -16px;
transform: translateY(-100%);
}
.timeline ol li:nth-child(odd) div::before {
top: 100%;
border-width: 8px 8px 0 0;
border-color: white transparent transparent transparent;
}
.timeline ol li:nth-child(even) div {
top: calc(100% + 16px);
}
.timeline ol li:nth-child(even) div::before {
top: -8px;
border-width: 8px 0 0 8px;
border-color: transparent transparent transparent white;
}
<section class="timeline">
<ol>
<li>
<div>
<time>2015</time> CHIWEN B.V. established
</div>
</li>
<li>
<div>
<time>2016</time> Established long-term research partnership with University of Groningen
</div>
</li>
<li>
<div>
<time>2017</time> Research on machine learning, deep learning, distributed training, brain-inspired pattern recognition algorithms, Neo4J and Blockchain, and distributed computing
</div>
</li>
<li>
<div>
<time>2018 Jan-Mar</time> Started TuDoLink project Team building Project Feasibility Analysis
</div>
</li>
<li>
<div>
<time>2018 Apr-Jul</time> System Framework Design Social Interaction Optimize Partnerships Optimize Business Plan Seed Funding Prepare MVP Prepare Pre-ICO Active on Social Media
</div>
</li>
<li>
<div>
<time>2018 Aug-Dec</time> MVP Development Collect Feedbacks of MVP Improve and Update MVP Optimize Team Development Optimize Business Development Release System Beta V1.0 System Testing Prepare ICO Prepare to List
</div>
</li>
<li>
<div>
<time>2019 Jan-Jun</time> ICO List Tokens Release APP & Trading Platform V1.0 Works on most of CPUs, GPUs, VPUs Distribute Globally
</div>
</li>
</ol>
</section>
解决方案
Using a CSS grid with 2 rows, each segment of the timeline can be defined to be 2 columns wide. Making the 2nd segment 3 columns wide instantly gives you a staggered layout. I built mine as a description list, but this is the basic idea:
dl {
display: grid;
grid-auto-columns: max-content;
grid-auto-flow: column;
grid-template-rows: auto auto;
}
.cell {
grid-column: span 2;
}
.cell:nth-child(2) {
grid-column: span 3;
}
推荐阅读
- python - 如何在 Windows 10 上使用 python 从 BT 模块 (HC-05) 接收数据?
- javascript - 传递“this”抛出函数
- swiftui - 重命名模式表上的取消按钮
- r - 将每一行除以R中的前一行
- active-directory - 我希望迁移 adb2c,但旧广告使用由 userflow 实现的 mfa。如何获得strongAuthenticationPhoneNumber?
- c# - 为什么在使用数据模板时视图的数据上下文是视图模型?
- kubernetes - 在 Ingress-Nginx 上接收请求后,如何使用 Keycloak(用于身份验证/授权)作为中间件?
- javascript - 使用动态 html 表格的内容
- r - 如何根据向量元素在列表中的位置替换它们?
- psycopg2 - 我正在尝试在我的 Mac 上安装 django-heroku,但出现以下错误