用纯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实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

在Linux中改变echo输出颜色的实现方法

《在Linux中改变echo输出颜色的实现方法》在Linux系统的命令行环境下,为了使输出信息更加清晰、突出,便于用户快速识别和区分不同类型的信息,常常需要改变echo命令的输出颜色,所以本文给大家介... 目python录在linux中改变echo输出颜色的方法技术背景实现步骤使用ANSI转义码使用tpu

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

golang版本升级如何实现

《golang版本升级如何实现》:本文主要介绍golang版本升级如何实现问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录golanwww.chinasem.cng版本升级linux上golang版本升级删除golang旧版本安装golang最新版本总结gola

SpringBoot中SM2公钥加密、私钥解密的实现示例详解

《SpringBoot中SM2公钥加密、私钥解密的实现示例详解》本文介绍了如何在SpringBoot项目中实现SM2公钥加密和私钥解密的功能,通过使用Hutool库和BouncyCastle依赖,简化... 目录一、前言1、加密信息(示例)2、加密结果(示例)二、实现代码1、yml文件配置2、创建SM2工具

Mysql实现范围分区表(新增、删除、重组、查看)

《Mysql实现范围分区表(新增、删除、重组、查看)》MySQL分区表的四种类型(范围、哈希、列表、键值),主要介绍了范围分区的创建、查询、添加、删除及重组织操作,具有一定的参考价值,感兴趣的可以了解... 目录一、mysql分区表分类二、范围分区(Range Partitioning1、新建分区表:2、分

MySQL 定时新增分区的实现示例

《MySQL定时新增分区的实现示例》本文主要介绍了通过存储过程和定时任务实现MySQL分区的自动创建,解决大数据量下手动维护的繁琐问题,具有一定的参考价值,感兴趣的可以了解一下... mysql创建好分区之后,有时候会需要自动创建分区。比如,一些表数据量非常大,有些数据是热点数据,按照日期分区MululbU