用纯CSS实现简单的纵向时间轴

2023-11-05 18:59

本文主要是介绍用纯CSS实现简单的纵向时间轴,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

特别感谢

https://www.lingtings.com/demo/html/2017/09/13/18_time_axis/

效果

在这里插入图片描述

CSS实现思路及注意事项

  1. :nth-child(even):nth-child(odd) 选择器,实现对奇偶数元素样式的批量设置。
  2. . margin-left: 50%;,使用百分数。
  3. position: abusolute;,使用绝对定位调整位置。
  4. 时间轴的轴线、文字气泡的箭头部分,可使用 ::before::after 伪元素实现。
  5. 主体文字部分不可使用绝对定位,否则全部脱离文档流,无法撑开最外层box。

代码

HTML部分
<body><div class="con"><h2 class="title">周杰伦作品集</h2><div class="timeline-con"><div class="timeline-post"><div class="timeline-date">2000</div><div class="timeline-icon-con"><div class="timeline-icon"><div class="timeline-icon-inner"></div></div></div><div class="timeline-content"><h3>Jay</h3><p>由周杰伦制作、作曲,方文山、徐若瑄等人作词,收录了10首歌曲,2000年11月7日发行 ,2001年,该专辑获得台湾金曲奖最佳流行音乐演唱专辑奖、IFPI香港唱片销量大奖十大销量国语唱片等奖项。</p> </div></div><div class="timeline-post"><div class="timeline-date">2001</div><div class="timeline-icon-con"><div class="timeline-icon"><div class="timeline-icon-inner"></div></div></div><div class="timeline-content"><h3>范特西</h3><p>共收录10首歌曲。该专辑的制作人由周杰伦担任。2002年,该专辑获得第十三届金曲奖颁奖礼最佳流行音乐专辑奖、新加坡金曲奖年度最畅销专辑等奖项。周杰伦凭借该专辑获得第十三届金曲奖颁奖最佳专辑制作人奖、第二届全球华语歌曲排行榜颁奖礼最佳制作人等奖项。</p> </div></div><div class="timeline-post"><div class="timeline-date">2002</div><div class="timeline-icon-con"><div class="timeline-icon"><div class="timeline-icon-inner"></div></div></div><div class="timeline-content"><h3>八度空间</h3><p>由周杰伦作曲并担任制作人,方文山、许世昌、刘耕宏、周杰伦作词。专辑于2002年7月18日发行,共收录10首歌曲。</p> </div></div><div class="timeline-post"><div class="timeline-date">2003</div><div class="timeline-icon-con"><div class="timeline-icon"><div class="timeline-icon-inner"></div></div></div><div class="timeline-content"><h3>叶惠美</h3><p>共收录了11首歌曲。专辑的制作人由周杰伦担任。2004年,该专辑获得了第15届金曲奖最佳流行音乐演唱专辑奖、新城国语力颁奖礼新城国语力亚洲大碟奖、第四届全球华语歌曲排行榜颁奖典礼年度最受欢迎专辑奖。</p> </div></div><div class="timeline-post"><div class="timeline-date">2004</div><div class="timeline-icon-con"><div class="timeline-icon"><div class="timeline-icon-inner"></div></div></div><div class="timeline-content"><h3>七里香</h3><p>该专辑的制作人由周杰伦担任,共收录了10首歌曲。2005年,该专辑获得第16届台湾金曲奖年度最佳专辑提名、HITO流行音乐奖年度DJ最爱专辑等奖项。</p> </div></div></div></div>
</body>
CSS部分
<style>* {padding: 0;margin: 0;}body {font-family:'Courier New', Courier, monospace, sans-serif;}.con {width: 1000px;margin: 0 auto;}.title {text-align: center;font-size: 24px;color: #333;margin-top: 50px;text-align: center;    }.timeline-con {position: relative;margin: 100px 30px;position: relative;}.timeline-con::before {content: '';display: block;width: 1px;height: 100%;background: linear-gradient(#feeeed , #f05b72, #feeeed);background: -webkit-linear-gradient(#feeeed , #f05b72, #feeeed);background: -o-linear-gradient(#feeeed , #f05b72, #feeeed);background: -moz-linear-gradient(#feeeed , #f05b72, #feeeed); position: absolute;left: 50%;top: 0;}.timeline-post {width: 50%;margin-left: 50%;margin-bottom: 60px;}.timeline-post:nth-child(even) {margin-left: 0;}.timeline-date {font-size: 20px;font-weight: bold;color: #666;position: absolute;right: 50%;margin-top: 15px;margin-right: 24px;}.timeline-post:nth-child(even) .timeline-date {left: 50%;margin-left: 24px;}.timeline-icon-con {width: 38px;height: 50px;background-color: #fff;display: flex;justify-content: center;align-items: center;position: absolute;left: 50%;margin-left: -18px;}.timeline-icon {width: 16px;height: 16px;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;-ms-border-radius: 50%;-o-border-radius: 50%;border: 3px solid #d93a49;}.timeline-content {position: relative;top: -6px;font-size: 18px;color: #666;line-height: 36px;margin: 0 0 0 44px;padding: 15px 16px 20px;background-color: #ffeeed;  border-radius: 5px;-webkit-border-radius: 5px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;}.timeline-post:nth-child(even) .timeline-content {margin: 0 44px 0 0;text-align: right;}.timeline-post:nth-child(odd) .timeline-content::before {content: '';display: inline-block;width: 0;height: 0;border-top: 8px solid transparent;border-right: 16px solid #ffeeed;border-bottom: 8px solid transparent;border-left: 16px solid transparent;position: absolute;top: 22px;left: -30px;}.timeline-post:nth-child(even) .timeline-content::after {content: '';display: inline-block;width: 0;height: 0;border-top: 8px solid transparent;border-right: 16px solid transparent;border-bottom: 8px solid transparent;border-left: 16px solid #ffeeed;position: absolute;top: 22px;right: -30px;}.timeline-content h3 {font-size: 18px;color: #f05b72;}.timeline-content p {margin-top: 0;}
</style>

这篇关于用纯CSS实现简单的纵向时间轴的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/351855

相关文章

Python实现终端清屏的几种方式详解

《Python实现终端清屏的几种方式详解》在使用Python进行终端交互式编程时,我们经常需要清空当前终端屏幕的内容,本文为大家整理了几种常见的实现方法,有需要的小伙伴可以参考下... 目录方法一:使用 `os` 模块调用系统命令方法二:使用 `subprocess` 模块执行命令方法三:打印多个换行符模拟

SpringBoot+EasyPOI轻松实现Excel和Word导出PDF

《SpringBoot+EasyPOI轻松实现Excel和Word导出PDF》在企业级开发中,将Excel和Word文档导出为PDF是常见需求,本文将结合​​EasyPOI和​​Aspose系列工具实... 目录一、环境准备与依赖配置1.1 方案选型1.2 依赖配置(商业库方案)二、Excel 导出 PDF

Python实现MQTT通信的示例代码

《Python实现MQTT通信的示例代码》本文主要介绍了Python实现MQTT通信的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 安装paho-mqtt库‌2. 搭建MQTT代理服务器(Broker)‌‌3. pytho

使用zip4j实现Java中的ZIP文件加密压缩的操作方法

《使用zip4j实现Java中的ZIP文件加密压缩的操作方法》本文介绍如何通过Maven集成zip4j1.3.2库创建带密码保护的ZIP文件,涵盖依赖配置、代码示例及加密原理,确保数据安全性,感兴趣的... 目录1. zip4j库介绍和版本1.1 zip4j库概述1.2 zip4j的版本演变1.3 zip4

python生成随机唯一id的几种实现方法

《python生成随机唯一id的几种实现方法》在Python中生成随机唯一ID有多种方法,根据不同的需求场景可以选择最适合的方案,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习... 目录方法 1:使用 UUID 模块(推荐)方法 2:使用 Secrets 模块(安全敏感场景)方法

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

Spring Boot 结合 WxJava 实现文章上传微信公众号草稿箱与群发

《SpringBoot结合WxJava实现文章上传微信公众号草稿箱与群发》本文将详细介绍如何使用SpringBoot框架结合WxJava开发工具包,实现文章上传到微信公众号草稿箱以及群发功能,... 目录一、项目环境准备1.1 开发环境1.2 微信公众号准备二、Spring Boot 项目搭建2.1 创建

IntelliJ IDEA2025创建SpringBoot项目的实现步骤

《IntelliJIDEA2025创建SpringBoot项目的实现步骤》本文主要介绍了IntelliJIDEA2025创建SpringBoot项目的实现步骤,文中通过示例代码介绍的非常详细,对大家... 目录一、创建 Spring Boot 项目1. 新建项目2. 基础配置3. 选择依赖4. 生成项目5.

Linux下删除乱码文件和目录的实现方式

《Linux下删除乱码文件和目录的实现方式》:本文主要介绍Linux下删除乱码文件和目录的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux下删除乱码文件和目录方法1方法2总结Linux下删除乱码文件和目录方法1使用ls -i命令找到文件或目录

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并