用纯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位移操作和位运算的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 位移操作1.1 左移操作 (<<)1.2 右移操作 (>>)注意事项:2. 位运算2.1

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

利用python实现对excel文件进行加密

《利用python实现对excel文件进行加密》由于文件内容的私密性,需要对Excel文件进行加密,保护文件以免给第三方看到,本文将以Python语言为例,和大家讲讲如何对Excel文件进行加密,感兴... 目录前言方法一:使用pywin32库(仅限Windows)方法二:使用msoffcrypto-too

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

使用Python实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1