基于ccs3的timeline時(shí)間線實(shí)現(xiàn)方法

在web項(xiàng)目中我們經(jīng)常要使用時(shí)間軸(timeline)控件。本文提供一種基于CSS3的可逐項(xiàng)展開的timeline,在各展開項(xiàng)中可以嵌入文本、圖片、視頻等元素。運(yùn)行效果如下:
實(shí)現(xiàn)
該控件的實(shí)現(xiàn)過程較為簡(jiǎn)單,主要由test.html
文件和timeline.css
文件組成。具體代碼如下:
1、test.html文件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="timeline.css"/> <title>Timeline</title> </head> <body> <div id='timeDiv'> <ul id='timeline'> <li class='work'> <input class='radio' id='work1' name='works' type='radio' checked> <div class="relative"> <label for='work1'>1、標(biāo)題一</label> <span class='date'>T1</span> <span class='circle'></span> </div> <div class='content'> <p> 長(zhǎng)安元年(701年),李白,字太白。其生地今一般認(rèn)為是唐劍南道綿州(巴西郡)昌?。ê蟊苄谥M改為昌明)青蓮鄉(xiāng)。祖籍為甘肅天水。 其家世、家族皆不詳。據(jù)《新唐書》記載,李白為興圣皇帝(涼武昭王李暠)九世孫,按照這個(gè)說法李白與李唐諸王同宗,是唐太宗李世民的同輩族弟。 亦有說其祖是李建成或李元吉。 </p> <p><img src="http://i.qulishi.com/UploadFile/2014-7/2014725171362.jpg" /></p> </div> </li> <li class='work'> <input class='radio' id='work2' name='works' type='radio'> <div class="relative"> <label for='work2'>2、標(biāo)題二</label> <span class='date'>T2</span> <span class='circle'></span> </div> <div class='content'> <p> 神龍?jiān)辏?05年), 十一月,武則天去世。李白五歲。發(fā)蒙讀書始于是年。 《上安州裴長(zhǎng)史書》云:“五歲誦六甲。”六甲,唐代的小學(xué)識(shí)字課本,長(zhǎng)史,州之次官。 </p> </div> </li> <li class='work'> <input class='radio' id='work3' name='works' type='radio'> <div class="relative"> <label for='work3'>3、標(biāo)題三</label> <span class='date'>T3</span> <span class='circle'></span> </div> <div class='content'> <p> 開元三年(715年),李白十五歲。 已有詩(shī)賦多首,并得到一些社會(huì)名流的推崇與獎(jiǎng)掖,開始從事社會(huì)干謁活動(dòng)。 亦開始接受道家思想的影響,好劍術(shù),喜任俠。是年岑參生。 </p> </div> </li> <li class='work'> <input class='radio' id='work4' name='works' type='radio'> <div class="relative"> <label for='work4'>4、標(biāo)題四</label> <span class='date'>T4</span> <span class='circle'></span> </div> <div class='content'> <p> 開元六年(718年),李白十八歲。 隱居戴天大匡山(在今四川省江油市內(nèi))讀書。 往來于旁郡,先后出游江油、劍閣、梓州(州治在今四川省境內(nèi))等地,增長(zhǎng)了不少閱歷與見識(shí)。 </p> </div> </li> </ul> </div> </body> </html>
2、timeline.css文件
#timeDiv{ max-width: 1200px; margin: 0 auto; padding: 0 5%; font-size: 100%; font-family: "Noto Sans", sans-serif; color: black; background: white; } /* ------------------------------------- * timeline * ------------------------------------- */ #timeline { list-style: none; margin: 50px 0 30px 120px; padding-left: 30px; border-left: 8px solid gray; } #timeline li { margin: 40px 0; position: relative; } #timeline p { margin: 0 0 15px; } .date { margin-top: -10px; top: 50%; left: -80px; font-size: 0.95em; line-height: 20px; position: absolute; } .circle { margin-top: -15px; top: 50%; left: -49px; width: 20px; height: 20px; background: white; border: 5px solid gray; border-radius: 50%; display: block; position: absolute; } .content { max-height: 20px; padding: 70px 20px 0; border-color: transparent; border-width: 2px; border-style: solid; border-radius: 0.5em; position: relative; } .content:before, .content:after { content: ""; width: 0; height: 0; border: solid transparent; position: absolute; pointer-events: none; right: 100%; } .content:before { border-right-color: inherit; border-width: 20px; top: 50%; margin-top: -20px; } .content:after { border-right-color: white; border-width: 17px; top: 50%; margin-top: -17px; } .content p { max-height: 0; color: transparent; text-align: justify; word-break: break-word; hyphens: auto; overflow: hidden; } label { font-size: 1.3em; position: absolute; z-index: 100; cursor: pointer; top: 35px; transition: transform 0.2s linear; font-weight: bold; } .radio { display: none; } .radio:checked + .relative label { cursor: auto; transform: translateX(42px); } .radio:checked + .relative .circle { background: red; } .radio:checked ~ .content { max-height: 200000px; border-color: lightgray; margin-right: 20px; transform: translateX(20px); transition: max-height 0.4s linear, border-color 0.5s linear, transform 0.2s linear; } .radio:checked ~ .content p { max-height: 200000px; color: black; transition: color 0.3s linear 0.3s; } /* ------------------------------------- * mobile phones (vertical version only) * ------------------------------------- */ @media screen and (max-width: 767px) { #timeline { margin-left: 0; padding-left: 0; border-left: none; } #timeline li { margin: 50px 0; } label { width: 85%; font-size: 1.1em; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; display: block; transform: translateX(18px); } .content { padding-top: 60px; border-color: #eee9dc; } .content:before, .content:after { border: solid transparent; bottom: 100%; } .content:before { border-bottom-color: inherit; border-width: 17px; top: -16px; left: 50px; margin-left: -17px; } .content:after { border-bottom-color: white; border-width: 20px; top: -20px; left: 50px; margin-left: -20px; } .content p { font-size: 0.9em; line-height: 1.4; } .circle, .date { display: none; } }
【參考文獻(xiàn)】 CSS3 TIMELINE
到此這篇關(guān)于基于ccs3的timeline時(shí)間線實(shí)現(xiàn)方法的文章就介紹到這了,更多相關(guān)css3 timeline實(shí)現(xiàn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
CSS3 最強(qiáng)二維布局系統(tǒng)之Grid 網(wǎng)格布局
CS3的Grid網(wǎng)格布局是目前最強(qiáng)的二維布局系統(tǒng),可以同時(shí)對(duì)列和行進(jìn)行處理,將網(wǎng)頁(yè)劃分成一個(gè)個(gè)網(wǎng)格,可以任意組合不同的網(wǎng)格,做出各種各樣的布局,本文介紹CSS3 最強(qiáng)二維布局系2025-02-27- 本文介紹了如何使用CSS3的transform屬性和動(dòng)畫技巧實(shí)現(xiàn)波浪式圖片墻,通過設(shè)置圖片的垂直偏移量,并使用動(dòng)畫使其周期性地改變位置,可以創(chuàng)建出動(dòng)態(tài)且具有波浪效果的圖片墻,同2025-02-27
CSS3模擬實(shí)現(xiàn)一個(gè)雷達(dá)探測(cè)掃描動(dòng)畫特效(最新推薦)
文章介紹了如何使用CSS3實(shí)現(xiàn)一個(gè)雷達(dá)探測(cè)掃描的效果,包括夜色背景、蜘蛛網(wǎng)盤、掃描體的轉(zhuǎn)動(dòng)效果、尾巴陰影以及被掃描到的光點(diǎn),通過HTML和CSS的配合,實(shí)現(xiàn)了豐富的動(dòng)畫效果,2025-02-21- CSS3的Flexbox是一種強(qiáng)大的布局模式,通過設(shè)置display:flex可以輕松實(shí)現(xiàn)對(duì)齊、排列和分布網(wǎng)頁(yè)元素,它解決了傳統(tǒng)布局方法中的對(duì)齊、間距分配和自適應(yīng)布局等問題,接下來通過本2025-02-19
css3 實(shí)現(xiàn)icon刷新轉(zhuǎn)動(dòng)效果
本文給大家介紹css3 實(shí)現(xiàn)icon刷新轉(zhuǎn)動(dòng)效果,文章開頭給大家介紹了webkit-transform、animation、@keyframes這三個(gè)屬性,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一2025-02-19CSS3動(dòng)態(tài)效果之過渡屬性(最新推薦)
CSS3過渡屬性用于實(shí)現(xiàn)元素從一種樣式平滑過渡到另一種樣式,通過設(shè)置transition-property過渡屬性、transition-duration過渡時(shí)長(zhǎng)transition-timing-function過渡函數(shù)和trans2025-02-19CSS3實(shí)現(xiàn)動(dòng)態(tài)旋轉(zhuǎn)加載樣式的示例代碼
本文介紹了如何使用CSS3創(chuàng)建一個(gè)簡(jiǎn)單的動(dòng)態(tài)旋轉(zhuǎn)加載樣式,通過定義一個(gè)帶有類名“l(fā)oader”的HTML元素,并使用CSS樣式和@keyframes規(guī)則來實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫,你可以根據(jù)需要調(diào)整樣式2025-02-19使用CSS3實(shí)現(xiàn)平滑的過渡動(dòng)畫效果(實(shí)例代碼)
這篇文章主要介紹了如何使用CSS3的transition屬性實(shí)現(xiàn)平滑的過渡動(dòng)畫,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2025-02-13CSS3中使用flex和grid實(shí)現(xiàn)等高元素布局的示例代碼
本文介紹了使用CSS3中的Flexbox和Grid布局實(shí)現(xiàn)等高元素布局的方法,通過簡(jiǎn)單的兩列實(shí)現(xiàn)、每行放置3列以及全部代碼的展示,展示了這兩種布局方式的實(shí)現(xiàn)細(xì)節(jié)和效果,感興趣的朋2025-02-11使用CSS3和SVG創(chuàng)建圓形進(jìn)度條動(dòng)畫效果
CSS3和SVG的結(jié)合使用為網(wǎng)頁(yè)設(shè)計(jì)帶來了創(chuàng)新的動(dòng)態(tài)視覺效果,本文通過一個(gè)圓形進(jìn)度條的動(dòng)畫特效示例,展示了如何利用CSS3的動(dòng)畫功能和SVG的矢量圖形能力來創(chuàng)建豐富的用戶交互體2024-10-24