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>
相关推荐
2501_915918416 小时前
iOS App 拿不到数据怎么办?数据解密导出到分析结构方法
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_916008896 小时前
iOS App 抓包看不到内容,从有请求没数据一步步排查
android·ios·小程序·https·uni-app·iphone·webview
扶苏10026 小时前
记一次 uni-app开发微信小程序 textarea 的“伪遮挡”踩坑实录
微信小程序·小程序·uni-app
RuoyiOffice1 天前
企业请假销假系统设计实战:一张表、一套流程、两段生命周期——BPM节点驱动的表单变形术
java·spring·uni-app·vue·产品运营·ruoyi·anti-design-vue
KongHen021 天前
uniapp-x实现自定义tabbar
前端·javascript·uni-app·unix
RuoyiOffice1 天前
SpringBoot+Vue3+Uniapp实现PC+APP双端考勤打卡设计:GPS围栏/内网双模打卡、节假日方案、定时预生成——附数据结构和核心源码讲解
java·spring·小程序·uni-app·vue·产品运营·ruoyi
2501_915921431 天前
2026 iOS 上架新趋势 iOS 发布流程模块化
android·ios·小程序·https·uni-app·iphone·webview
窝子面2 天前
uni-app的初体验
uni-app
笨笨狗吞噬者2 天前
【uniapp】微信小程序实现自定义 tabBar
前端·微信小程序·uni-app
雪芽蓝域zzs2 天前
uniapp MD5加密 加密传输 密码加密
uni-app