uniapp 手写 简易 时间轴 组件

一、案例如图

该案例设计条件:

左侧时间 和竖线、点、内容都是居中对其的,上下时间点中间要有一段距离

二、编写逻辑

  1. 布局结构:一共三个元素,左侧是时间和黑点,中间是线条,右侧是内容

  2. 样式难点:让子元素撑满父元素高度,通过给父元素 align-items: stretch;

如何让内容居中对其?

答:以左侧为例子,左侧高度为父元素高度,它里有开始时间、结束时间、黑点,只需要设置 justify-content: center;aligns-item:center;右侧同理

如何让线条line边长,让上下内容有一段距离?

答:只能单独设置一个div,让它的样式与 线的样式相同,有一个高度,用来隔开一段距离(暂时想到这个方法,有点麻烦)

三、代码案例(没时间一步一步去写如何思考的,太忙了,赶着开发)

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>盛满父元素高度</title>
    <style>
      .father {
        display: flex;
        flex-direction: row;
        align-items: stretch;
      }
      .son1 {
        background-color: yellowgreen;
        width: 4px;
        padding: 60px 0; /* 通过padding 让线条变长,使上下模块产生距离 */
        margin: 0 10px;
      }
      .son2 {
        width: 200px;
        background-color: #d3e3fd;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .circle {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background-color: #000;
        position: relative;
        left: 47px;
      }

      .time {
        width: 40px;
        display: flex;
        flex-direction: column;
        justify-content: center;
      }
      .jianxi{
        background-color: yellowgreen;
        width: 4px;
        margin: 0 10px;
        height: 20px;
        position: relative;
        left: 40px;
      }
    </style>
  </head>
  <body>
    <div class="father">
      <div class="time">
        <div>9:30</div>
        <div class="circle"></div>
        <div>9:45</div>
      </div>
      <div class="son1"></div>
      <div class="son2">这是子元素son2,它里面有很多内容,可以撑起一个高度</div>
    </div>
    <div class="jianxi"></div>
    <div class="father">
      <div class="time">
        <div>10:30</div>
        <div class="circle"></div>
        <div>10:45</div>
      </div>
      <div class="son1"></div>
      <div class="son2">
        这是子元素son2,它里面有很多内容,可以撑起一个高度,这是子元素son2,它里面有很多内容,可以撑起一个高度这是子元素son2,它里面有很多内容,可以撑起一个高度
      </div>
    </div>
  </body>
</html>
相关推荐
小徐_23332 天前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
iOS阿玮2 天前
永远不要站在用户的对立面,挑战大众的公知。
uni-app·app·apple
xw52 天前
uni-app中v-if使用”异常”
前端·uni-app
!win !2 天前
uni-app中v-if使用”异常”
前端·uni-app
2501_915918412 天前
iOS 上架全流程指南 iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传 ipa 与审核实战经验分享
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张2 天前
iOS App 混淆与加固对比 源码混淆与ipa文件混淆的区别、iOS代码保护与应用安全场景最佳实践
android·安全·ios·小程序·uni-app·iphone·webview
00后程序员张3 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
海绵宝宝不喜欢侬3 天前
uniapp-微信小程序分享功能-onShareAppMessage
微信小程序·小程序·uni-app
2501_915106323 天前
Xcode 上传 ipa 全流程详解 App Store 上架流程、uni-app 生成 ipa 文件上传与审核指南
android·macos·ios·小程序·uni-app·iphone·xcode
xkxnq3 天前
Uniapp崩溃监控体系构建:内存泄漏三维定位法(堆栈/资源/线程)
uni-app