用纯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

相关文章

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉,那么对 shallowRef 和 shallowReactive 是否了解呢? 在编程和数据结构中,“shallow”(浅层)通常指对数据结构的最外层进行操作,而不递归地处理其内部或嵌套的数据。这种处理方式关注的是数据结构的第一层属性或元素,而忽略更深层次的嵌套内容。 1. 浅层与深层的对比 1.1 浅层(Shallow) 定义

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

【 html+css 绚丽Loading 】000046 三才归元阵

前言:哈喽,大家好,今天给大家分享html+css 绚丽Loading!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 📚一、效果📚二、信息💡1.简介:💡2.外观描述:💡3.使用方式:💡4.战斗方式:💡5.提升:💡6.传说: 📚三、源代码,上代码,可以直接复制使用🎥效果🗂️目录✍️

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

hdu2289(简单二分)

虽说是简单二分,但是我还是wa死了  题意:已知圆台的体积,求高度 首先要知道圆台体积怎么求:设上下底的半径分别为r1,r2,高为h,V = PI*(r1*r1+r1*r2+r2*r2)*h/3 然后以h进行二分 代码如下: #include<iostream>#include<algorithm>#include<cstring>#include<stack>#includ

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time