技术频道导航
HTML/CSS
.NET技术
IIS技术
PHP技术
Js/JQuery
Photoshop
Fireworks
服务器技术
操作系统
网站运营

赞助商

分类目录

赞助商

最新文章

搜索

纯css实现的自适应的垂直时间线

作者:admin    时间:2021-7-25 16:15:6    浏览:

互联网用户喜欢使信息更容易消化的图形。垂直时间线可以讲述你公司的故事及其发展历程。它可以揭示产品或服务的演变,讨论特定行业的历史,甚至可以引导你的客户完成你提供服务的过程。最重要的是,你可以使用一点 CSS 就能在自己的网站上创建垂直时间线。

本文介绍的是一个可以自适应的垂直时间线。

时间线

时间线

从 HTML 开始

你的网页上的 HTML 标记为你的时间线提供内容,下面是示例代码:

<!-- main timeline section -->
<section id="cd-timeline" class="cd-container cssanimations">
  <!-- single timeline event -->
  <div class="cd-timeline-block">
    <div class="cd-timeline-img cd-picture">
      <img src="event-calender.png" />
    </div>
    <div class="cd-timeline-content">
      <h2>Event 1</h2>
      <p>Event 1 Description </p>
      <span class="cd-date">Sunday, 19 June 2016</span>
    </div>
  </div>
  ....
  ....
</section>

上面的示例是时间线上的单个事件,你只需通过在代码的第 3 行和第 8 行之间复制,相应地修改它们并将它们粘贴到第 8 行和第 9 行之间来插入附加事件,为你想要添加到时间线的尽可能多的事件执行此操作。

设计你的时间线

你可以使用标准 HTML 标记来设置时间线的样式,但这非常耗时且相当多余。最好改用 CSS 样式。下面是一些基本 CSS 样式的示例代码;你必须使用单独的代码来设置各个元素的样式:

#cd-timeline {
  position: relative;
  padding: 2em 0;
  margin-top: 2em;
  margin-bottom: 2em;
}
#cd-timeline::before {
  /* this is the vertical line */
  content: '';
  position: absolute;
  top: 0;
  height: 100%;
  width: 4px;
  background: #d7e4ed;
  left: 50%;
  margin-left: -2px;
}
.cd-container::after {
  content: '';
  display: table;
  clear: both;
}
.cd-container {
  width: 90%;
  max-width: 1170px;
  margin: 0 auto;
}
.cd-timeline-block:first-child {
  margin-top: 0;
}
.cd-timeline-block {
  position: relative;
      margin: 4em 0;
}
.cd-timeline-content {
  margin-left: 0;
  padding: 1.6em;
  width: 42%;
  position: relative;
  background: white;
  border-radius: 0.25em;
  padding: 1em;
  box-shadow: 0 3px 0 #d7e4ed;
}
.cd-timeline-content .cd-date {
  position: absolute;
  width: 100%;
  left: 122%;
  top: 6px;
  font-size: 16px;
  font-size: 1rem;
}
.cd-timeline-block:nth-child(even) .cd-timeline-content .cd-date {
  left: auto;
  right: 122%;
  text-align: right;
}
.cd-timeline-block:nth-child(even) .cd-timeline-content {
  float: right;
}
.cd-timeline-block:after {
  content: "";
  display: table;
  clear: both;
}
.cd-timeline-img {
  width: 60px;
  height: 60px;
  left: 50%;
  margin-left: -30px;
  -webkit-transform: translateZ(0);
  -webkit-backface-visibility: hidden;
}
.cd-timeline-img {
  position: absolute;
  top: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 4px white, inset 0 2px 0 rgba(0, 0, 0, 0.08), 0 3px 0 4px rgba(0, 0, 0, 0.05);
  background: #105a8b;
}
.cd-timeline-img img,.cd-timeline-img svg {
  display: block;
  width: 24px;
  height: 24px;
  position: relative;
  left: 50%;
  top: 50%;
  margin-left: -12px;
  margin-top: -12px;
  vertical-align: middle;
}
.cssanimations .cd-timeline-img.is-hidden,.cssanimations .cd-timeline-content.is-hidden {
  visibility: hidden;
}
.cssanimations .cd-timeline-img.bounce-in,.cssanimations .cd-timeline-content.bounce-in {
  visibility: visible;
  animation: cd-bounce-1 0.6s;
}
@keyframes cd-bounce-1 {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
  60% {
    opacity: 1;
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

execcodegetcode

你可以按照自己喜欢的任何方式设置时间线元素的样式,使用与以下相关的相应 CSS 规则:位置、底部、宽度、高度、填充、背景、边框样式。

一些 Web 开发人员更喜欢随着时间线的推移对元素进行不同的样式设置。例如,你可能希望为每个其他条目设置不同的样式,以便提供一种区分它们的方法。或者,你可以根据某个预先确定的类别设计不同的元素。

您可能对以下文章也感兴趣

标签: Timeline  时间线  
x
  • 站长推荐
/* 左侧显示文章内容目录 */