Notice: Undefined index: public in /www/wwwroot/cuixinxin.cn/wp-content/plugins/wpjam-basic/includes/class-wpjam-core.php on line 137

Notice: Undefined index: public in /www/wwwroot/cuixinxin.cn/wp-content/plugins/wpjam-basic/includes/class-wpjam-core.php on line 137
纯CSS实现带有画布边框和刻度尺的样式 卖坚果的怪叔叔
卖坚果的怪叔叔 卖坚果的怪叔叔
  • 首页
  • 生活
  • 技术
  • 记录
  • 工具箱
  • 关于我
首页 › 技术 › 纯CSS实现带有画布边框和刻度尺的样式

纯CSS实现带有画布边框和刻度尺的样式

坚果大叔
2023-11-27 16:48:06技术阅读 12,424

有一个ui需求需要实现类似在线画布功能那种边框带刻度尺的效果。主要是上边框和左边框需要实现此UI效果。

效果如下

纯CSS实现带有画布边框和刻度尺的样式-卖坚果的怪叔叔


纯CSS实现带有画布边框和刻度尺的样式-卖坚果的怪叔叔

除了上面的效果之外,还需要每个大刻度是需要点击选中的。并且选中还有单独的选中样式。

1、第一种想法就是通过div实现,大刻度用边框来实现,里面的小刻度用10个标签来实现。

2、通过css的background-image属性种 linear-gradient 方法来实现。

3、第一种和第二种结合,外侧大标签用border来实现,里面的小刻度用background-image来实现。

尝试过后可以完美实现刻度尺的样式。但是因为实际需求需要可以点击选中,而且选中后刻度颜色需要改变所以选中第三种方式来实现。

具体代码

数据结构

cemeteryData: [
    {
      name: 'B1',
      id: 'b1',
      active: false,
    },
    {
      name: 'B2',
      id: 'b2',
    },
]

HTML代码



{{ index + 1 }}列

CSS代码


.topScale {
  width: 100%;
  display: flex;

  .scaleItem {
    position: relative;
    flex: 1;
    height: 40px;
    text-align: center;
    cursor: pointer;
    border: 1px solid #83aef9;
    border-top: none;
    border-right: none;

    &:last-child {
      border-right: 1px solid #83aef9;
    }

    .scale {
      position: absolute;
      bottom: 0;
      left: 10%;
      width: 80%;
      height: 10px;
      background-image: linear-gradient(90deg, #83aef9 1px, transparent 0);
      background-size: 75px 0px, 11% 10px;
    }

    &.scaleActive {
      --active-color: #fddae2;
      background-color: var(--active-color);
      border-left-color: var(--active-color);
      border-bottom-color: var(--active-color);

      .scale {
        background-image: linear-gradient(90deg, var(--active-color) 1px, transparent 0);
      }

      &:last-child {
        border-right-color: var(--active-color);
      }

      + .scaleItem {
        border-left-color: var(--active-color);
      }
    }
  }
}

其中有两个地方需要注意,一个是 background-size: 75px 0px, 11% 10px; 设置横向的时候小刻度的间隔,10px是设置纵向的时候刻度的间隔。

还有个就是选中之后的样式,因为大标签的刻度是用的border来实现的。为防止边框重叠设置的右边框没有,只有最后一个元素的右边框才有。所以在选中的时候当前item的右边框是没有的,所以就需要将选中右侧item的左边框设置选中颜色。 通过 + .scaleItem来选中邻居class.

纯CSS实现带有画布边框和刻度尺的样式-卖坚果的怪叔叔

赞赏 赞(4)
远方
上一篇
TrollStore 2 已发布,附超详细安装教程~
下一篇
在小程序中查看

这是个😊,挣点服务器费用😜

热门文章
Mac更换node版本切换工具n模块的镜像源
iphone 利用 Scriptable 添加网上国网电费小组件
常用的JS 时间转换相关代码!
周末,公园,人多!!!
ES6入门之Symbol
新年快乐🎉
专题标签
agent (1) CSS (15) dom (1) Es6入门系列 (14) Git (3) html (1) iview (1) JavaScript (9) js (4) Lif (1) Node (4) pyecharts (1) Python (10) ref (1) scriptable (1) Skill (1) vsCode (1) vue (4) wordpress (2) 三月 (1) 上海 (1) 假期 (1) 其他分享 (3) 前端两三问 (15) 古镇 (1) 外滩 (1) 对象 (1) 小程序 (5) 年度总结 (6) 年终总结 (1) 微信机器人 (4) 打字机 (1) 技术 (1) 日常问题 (8) 日常问题记录 (1) 春天 (2) 服务器 (2) 海族馆 (1) 生活 (8) 网上国网 (1) 记录 (3) 通勤 (1) 重学JavaScript (11) 面试题 (10) 🌸 (1)
什么是Agent?
2026-08-15 23:49:12
487 0 2
什么是 Skill?
2026-08-12 21:32:42
402 1 0
失业在家,我给小朋友做了一个练字小程序!
2026-08-07 16:21:52
804 10 1
上线8年,15万用户的小程序,一共赚了多少钱?
2026-05-30 18:01:24
4,785 4 0
4
  • 4
博主

一位佛系的前端开发者,略通摄影,乐于尝试新事物,热衷于美食。

友链
故事胶片
公众号
坚果大叔 执行上下文 卖坚果的怪叔叔 Dacking
Copyright © 2017-2026 卖坚果的怪叔叔

开往-友链接力

萌ICP备20230818号

苏ICP备18048410号-3
  • 首页
  • 生活
  • 技术
  • 记录
  • 工具箱
  • 关于我
# CSS # # JavaScript # # vue # # 微信 # # 生活 #
坚果大叔
345
文章
171
评论
432
喜欢