html实现时间轴_纯css实现响应式竖着/垂直时间抽布局效果

yizhihongxing

HTML实现时间轴-纯CSS实现响应式竖着/垂直时间线布局效果

时间轴是现代网站设计中非常流行的一种设计元素。在该设计元素中,一系列日期和事件以时间线的形式展示出来。在本文中,我们将讨论如何使用HTML和CSS实现一个响应式、垂直排列的时间轴布局。

HTML代码结构

为了实现时间轴布局,我们需要定义一些HTML元素,如 ullip等。下面是时间轴布局HTML代码结构的一般模板:

<ul class="timeline">
  <li>
    <div class="timeline-badge">
      <i class="fa fa-plus"></i>
    </div>
    <div class="timeline-panel">
      <div class="timeline-heading">
        <h4 class="timeline-title">Event Title One</h4>
        <p><small class="text-muted"><i class="fa fa-clock-o"></i> Date</small></p>
      </div>
      <div class="timeline-body">
        <p>Event Description One</p>
      </div>
    </div>
  </li>
  <li class="timeline-inverted">
    <div class="timeline-badge">
      <i class="fa fa-minus"></i>
    </div>
    <div class="timeline-panel">
      <div class="timeline-heading">
        <h4 class="timeline-title">Event Title Two</h4>
        <p><small class="text-muted"><i class="fa fa-clock-o"></i> Date</small></p>
      </div>
      <div class="timeline-body">
        <p>Event Description Two</p>
      </div>
    </div>
  </li>
</ul>

在上面的代码中,我们将所有的时间轴事件嵌套在一个 ul 元素中。每个事件都被包含在一个 li 元素中。每个事件都有一个左侧的时间线点 timeline-badge ,一个包含事件细节的区域 timeline-panel

CSS样式

现在,让我们开始定义我们的CSS样式,使时间轴布局显得更加美观和易于阅读。下面是直接使用CSS样式实现时间轴布局的示例:

.timeline {
  list-style: none;
  padding: 20px 0 20px;
  position: relative;
}
.timeline:before {
  top: 0;
  bottom: 0;
  position: absolute;
  content: " ";
  width: 2px;
  background-color: #eeeeee;
  left: 50%;
  margin-left: -1.5px;
}
.timeline > li {
  margin-bottom: 20px;
  position: relative;
}
.timeline > li:before,
.timeline > li:after {
  content: " ";
  display: table;
}
.timeline > li:after {
  clear: both;
}
.timeline > li .timeline-badge {
  color: #fff;
  width: 50px;
  height: 50px;
  line-height: 50px;
  font-size: 1.4em;
  text-align: center;
  position: absolute;
  top: 16px;
  left: 50%;
  margin-left: -25px;
  background-color: #999999;
  border-radius: 50%;
  z-index: 100;
}
.timeline > li.timeline-inverted .timeline-badge {
  left: auto;
  right: 50%;
  margin-right: -25px;
}
.timeline > li.timeline-inverted .timeline-panel {
  float: right;
  /*改变事件细节内容的位置*/
}
.timeline > li.timeline-inverted .timeline-panel:before {
  border-left-width: 0;
  border-right-width: 15px;
  left: -15px;
  right: auto;
}
.timeline > li.timeline-inverted .timeline-panel:after {
  border-left-width: 0;
  border-right-width: 14px;
  left: -14px;
  right: auto;
}
.timeline > li .timeline-panel {
  width: 46%;
  float: left;
  /*改变事件细节内容的位置*/
  padding: 20px;
  border: 1px solid #d4d4d4;
  border-radius: 8px;
  background-color: #f4f4f4;
  position: relative;
  -webkit-box-shadow: -1px 1px 6px rgba(0, 0, 0, 0.2);
  -moz-box-shadow: -1px 1px 6px rgba(0, 0, 0, 0.2);
  box-shadow: -1px 1px 6px rgba(0, 0, 0, 0.2);
}
.timeline > li.timeline-inverted .timeline-panel {
  float: right;
  /*改变事件细节内容的位置*/
}
.timeline > li.timeline-inverted .timeline-panel:before {
  border-left-width: 0;
  border-right-width: 15px;
  left: -15px;
  right: auto;
}
.timeline > li.timeline-inverted .timeline-panel:after {
  border-left-width: 0;
  border-right-width: 14px;
  left: -14px;
  right: auto;
}
.timeline > .timeline-heading h4 {
  margin-top: 0;
  color: inherit;
}
.timeline > .timeline-heading h4 > small {
  color: #999999;
}
.timeline > li.timeline-inverted > .timeline-panel:before {
  border-right-color: #d4d4d4;
  border-right-width: 1px;
  border-left-color: transparent;
  border-left-width: 0;
}
.timeline > li.timeline-inverted > .timeline-panel:after {
  border-right-color: #f4f4f4;
  border-right-width: 1px;
  border-left-color: transparent;
  border-left-width: 0;
}

在上述CSS样式中,我们为时间轴布局定义了一些通用样式,如列表样式、填充、以及时间轴点和事件细节的距离等。我们还定义了一些针对时间轴点和事件细节定制的样式。

响应式设计

现代网站必须是响应式的,能够适应各种尺寸的设备。因此,让我们使用CSS媒体查询添加响应式设计。

@media all and (max-width: 768px) {
  .timeline:before {
    left: 40px;
  }
  .timeline > li > .timeline-panel {
    width: calc(100% - 90px);
    width: -webkit-calc(100% - 90px);
    /* Safari */
    width: -moz-calc(100% - 90px);
    /* Firefox */
  }
  .timeline > li > .timeline-badge {
    left: 15px;
    margin-left: 0;
    top: 10px;
  }
  .timeline > li {
    margin-bottom: 30px;
  }
  .timeline > li:last-child {
    margin-bottom: 0;
  }
  .timeline > li.timeline-inverted > .timeline-panel {
    float: right;
  }
  .timeline > li.timeline-inverted > .timeline-panel:before {
    border-left-width: 0;
    border-right-width: 15px;
    left: -15px;
    right: auto;
  }
  .timeline > li.timeline-inverted > .timeline-panel:after {
    border-left-width: 0;
    border-right-width: 14px;
    left: -14px;
    right: auto;
  }
}

在上述CSS代码中,我们定义了一个媒体查询,它在屏幕宽度小于等于 768px 时生效。在该媒体查询内,我们重新编排了时间轴布局的大小和位置,从而使其适应移动设备的屏幕尺寸。

结语

时间轴是一种很好的展示历史事件和进程的方式。使用HTML和CSS实现时间轴布局可以为现代网站增添非常酷炫的设计元素。本文提供了一个使用HTML和CSS实现时间轴布局的示例模板,并介绍了一些定制时间轴布局的CSS样式和响应式设计。

如果你想要在你的网站中添加时间轴布局,可以试试我们提供的这种实现方式。祝你实现想要的效果!

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:html实现时间轴_纯css实现响应式竖着/垂直时间抽布局效果 - Python技术站

(0)
上一篇 2023年3月28日
下一篇 2023年3月28日

相关文章

  • Android四大组件之Service服务详细讲解

    Android四大组件之Service服务详细讲解 什么是Service? Service是Android四大组件之一,它是在后台执行操作的组件,可以在不受用户干扰的情况下长时间运行。Service通常用于执行诸如下载、上传数据、播放音乐等耗时操作。 Service的分类 前台服务:与用户正在进行交互的Activity或者其他前台组件有关的服务。此类服务需要…

    other 2023年6月27日
    00
  • Java 数据结构七大排序使用分析

    Java 数据结构七大排序使用分析 在编写Java程序时,经常需要用到排序算法对数据进行排序,因此了解并掌握不同排序算法的优缺点以及使用场景,对于提高程序效率和优化程序结构都有很大的帮助。本文将介绍Java数据结构中常用的七大排序算法,并分析他们的使用场景,帮助读者选择最适合自己程序需求的算法。 1. 冒泡排序 冒泡排序是一种简单的排序算法,它的基本思想是通…

    other 2023年6月27日
    00
  • 使用squid搭建http代理的方法

    使用Squid搭建HTTP代理需要以下几个步骤: 安装Squid 在Ubuntu系统下使用以下命令安装Squid: sudo apt-get update sudo apt-get install squid 配置Squid 在安装完成后,Squid的配置文件位于/etc/squid/squid.conf。我们需要进行以下修改: 1. 确认监听端口 默认监听…

    other 2023年6月27日
    00
  • 怎么共享文件

    共享文件是指在不同的设备之间共享数据,可以是文档、照片、音乐等各种类型的文件。共享文件可以通过多种方式进行,例如使用本地网络、云存储、文件传输协议等方法。下面详细介绍其中的几种方法和具体操作步骤。 一、本地网络共享 本地网络共享指的是在本地网络内,将设备连接在同一局域网下,通过设置共享文件夹的方式进行文件共享。具体步骤如下: 将所有需要共享的设备连接进同一个…

    其他 2023年4月16日
    00
  • 魔兽世界8.0惩戒骑堆什么属性好 惩戒骑士属性收益及选择优先级

    魔兽世界8.0惩戒骑堆什么属性好 职业介绍 首先,我们需要了解一下惩戒骑士这个职业的特点和定位。惩戒骑士是一种以近战输出为主要特点的职业,其使用的主要武器是单手武器和盾牌或双手武器。其在团队中的主要作用是提供治疗和减伤,同时也需要承担部分坦克的职责。 属性收益及选择优先级 在对惩戒骑士进行属性选择的时候,我们需要考虑几个主要的属性,包括: 力量(Streng…

    other 2023年6月27日
    00
  • 魔兽世界8.0惩戒骑输出循环优先级介绍 惩戒骑输出手法

    魔兽世界8.0惩戒骑输出循环优先级介绍 1. 输出循环介绍 惩戒骑士在8.0版本中的输出循环优先级为:审判 >愤怒之锤>十字军打击(J)>断筋者(CS)>公正之剑(TV)>Exorcism(Exo)>奉献(CF)。 在战斗中,惩戒骑士需要尽量保证审判和愤怒之锤在每个冷却周期内能够有效施放。同时,需要优先使用有强化效果的技能…

    other 2023年6月27日
    00
  • Jquery弹出层插件ThickBox的使用方法

    Jquery弹出层插件ThickBox的使用方法 ThickBox是一款基于jQuery编写的弹出层插件,可用于快速创建弹出窗口、图片浏览、表单提交等效果。本文将详细介绍ThickBox的使用方法。 下载和引入ThickBox ThickBox的下载地址为:https://github.com/CodyLindley/ThickBox,下载后解压即可得到相关…

    other 2023年6月25日
    00
  • C语言初阶之数组详细介绍

    C语言初阶之数组详细介绍 数组的概念 在C语言中,数组是一种数据结构,是一系列相同类型的数据元素组成的集合。这些数据元素可以通过它们的下标进行访问,下标通常是整数。 数组的声明和初始化 数组的声明和初始化的语法格式如下: type arrayName[arraySize]; type arrayName[arraySize] = {value1, value…

    other 2023年6月25日
    00
合作推广
合作推广
分享本页
返回顶部