找回密码
 立即注册
搜索
查看: 316|回复: 1

[软件] 求助CSS高手,代码修改 (二)

[复制链接]
     
发表于 2025-11-21 16:39 | 显示全部楼层 |阅读模式
CSS代码,仿Chrome标签页(梯形标签页),用于文件管理软件Tablacus Explorer。



想做一个改进,就是提升文字位置,如图:




CSS代码(待修改)

  1. /* ============================================
  2.    基础设置与颜色定义
  3.    ============================================= */

  4. /* 1. 去除默认的边框、阴影和凸起效果 */
  5. .tab, .tab2, .tab3, .activetab,
  6. .tab:hover, .tab2:hover, .tab3:hover {
  7.   box-shadow: none !important;
  8.   border: none !important;
  9.   outline: none !important;
  10. }

  11. /* 2. 标签栏整体背景 */
  12. .tab0 {
  13.   /* 这里设置标签栏底色,建议使用深蓝灰色 */
  14.   background-color: #648ca5;
  15.   padding: 5px 0 0 10px; /* 顶部留点空隙,左侧留空隙 */
  16.   height: 30px; /* 强制高度,防止布局乱跳 */
  17. }

  18. /* =============================================
  19.    标签通用形状 (所有标签都生效的样式)
  20.    ============================================ */
  21. .tab, .tab2, .tab3, .activetab {
  22.   position: relative;
  23.   display: inline-block;
  24.   height: 26px;        /* 标签高度 */
  25.   line-height: 28px;   /* 文字垂直居中微调 */
  26.   padding: 0px 10px;     /* 文字左右间距 */
  27.   margin: 0 8px;       /* 标签之间的重叠/间距,负数可以让它们重叠 */
  28.   font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  29.   cursor: default;
  30.   vertical-align: top; /* 顶部对齐 */
  31. }

  32. /* 通用的伪元素设置 (用于显示梯形两侧) */
  33. .tab:before, .tab:after,
  34. .tab2:before, .tab2:after,
  35. .tab3:before, .tab3:after,
  36. .activetab:before, .activetab:after {
  37.   content: "";
  38.   position: absolute;
  39.   bottom: 0;
  40.   width: 25px;  /* SVG图片的宽度 */
  41.   height: 26px; /* 必须与标签高度一致 */
  42.   pointer-events: none; /* 防止鼠标点到圆角上没反应 */
  43. }

  44. /* 左侧圆角位置 */
  45. .tab:before, .tab2:before, .tab3:before, .activetab:before {
  46.   left: -21px; /* 根据SVG宽度调整,负值 */
  47. }

  48. /* 右侧圆角位置 (镜像翻转) */
  49. .tab:after, .tab2:after, .tab3:after, .activetab:after {
  50.   right: -21px;
  51.   transform: scaleX(-1);
  52. }

  53. /* =============================================
  54.    状态 A: 非当前页 (普通标签)
  55.    ============================================= */
  56. .tab, .tab2, .tab3 {
  57.   /* 非当前页背景色 (稍浅于底色,或灰色) */
  58.   background-color: #8daabb;
  59.   color: #FFFFFF; /* 非当前页文字颜色 */
  60.   z-index: 1;  /* 层级低,被当前页压住 */
  61. }

  62. /* 非当前页的梯形 SVG (填充色必须对应上面的 background-color: #8daabb) */
  63. .tab:before, .tab:after,
  64. .tab2:before, .tab2:after,
  65. .tab3:before, .tab3:after {
  66.   /* 下方 fill=%238daabb 就是颜色代码,如果改背景色,这里也要改 */
  67.   background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill%3D%22%238daabb%22%20d%3D%22M24%200C9%200%2015%2026%200%2026h25V0h-1z%22%2F%3E%3C%2Fsvg%3E");
  68. }

  69. /* ==============================================
  70.    状态 B: 鼠标悬停 (Hover)
  71.    ============================================= */
  72. .tab:hover, .tab2:hover, .tab3:hover {
  73.   /* 悬停时的背景色 (浅蓝色) */
  74.   background-color: #bfe0f0;
  75.   color: #000;
  76.   z-index: 5; /* 悬停时层级提高 */
  77. }

  78. /* 悬停时的梯形 SVG (填充色 fill=%23bfe0f0) */
  79. .tab:hover:before, .tab:hover:after,
  80. .tab2:hover:before, .tab2:hover:after,
  81. .tab3:hover:before, .tab3:hover:after {
  82.   background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill%3D%22%23bfe0f0%22%20d%3D%22M24%200C9%200%2015%2026%200%2026h25V0h-1z%22%2F%3E%3C%2Fsvg%3E");
  83. }

  84. /* =============================================
  85.    状态 C: 当前页 (Active)
  86.    ============================================= */
  87. .activetab {
  88.   /* 当前页背景色 (白色) */
  89.   background-color: #ffffff;
  90.   color: #000; /* 当前页文字颜色 */
  91.   z-index: 10; /* 层级最高,压在所有标签上面 */
  92.   font-weight: normal;

  93. }

  94. /* 当前页的梯形 SVG (填充色 fill=%23ffffff) */
  95. .activetab:before, .activetab:after {
  96.   background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill%3D%22%23ffffff%22%20d%3D%22M24%200C9%200%2015%2026%200%2026h25V0h-1z%22%2F%3E%3C%2Fsvg%3E");
  97. }
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

     
发表于 2025-11-21 17:22 | 显示全部楼层
帮你问了Gemini 3 Pro Preview:

这个问题主要是由于 line-height(行高)设置得过大导致的。

在你的代码中,标签的高度 (height) 是 26px,但行高 (line-height) 却设置成了 28px。对于“微软雅黑”这种字体,如果行高大于容器高度,文字往往会显得靠下(甚至压到底边)。

要解决这个问题,你需要减小 line-height 的数值。


解决方案

请找到 CSS 代码中的 “标签通用形状” 部分(大约第 24 行左右),修改 .tab, .tab2, .tab3, .activetab 这一段。

修改建议: 将 line-height: 28px; 改为 24px25px


修改后的代码段:

  1. /* =============================================
  2.    标签通用形状 (所有标签都生效的样式)
  3.    ============================================ */
  4. .tab, .tab2, .tab3, .activetab {
  5.   position: relative;
  6.   display: inline-block;
  7.   height: 26px;        /* 标签高度不变 */

  8.   /* --- 修改这里 --- */
  9.   line-height: 24px;   /* 原为28px。改为24px可以提升文字位置 */
  10.   /* ---------------- */

  11.   padding: 0px 10px;   /* 文字左右间距 */
  12.   margin: 0 8px;      
  13.   font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  14.   cursor: default;
  15.   vertical-align: top;
  16. }
复制代码


调整说明(如何微调):

  • 垂直居中:通常将 line-height 设置得比 height (26px) 稍小一点点(例如 25px 或 24px),在微软雅黑字体下视觉上才会居中。
  • 更靠顶部 (顶部间距2px):如果 24px 还是觉得不够高,可以尝试改为 22px。数值越小,文字越往上跑。

你可以先改为 24px 保存并刷新 Tablacus Explorer 查看效果,如果觉得还是偏低,就改成 22px。不要改动 height: 26px,否则会导致梯形图片错位。

评分

参与人数 1战斗力 +1 收起 理由
proof1 + 1 感谢! 我试试行不行。

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|上海互联网违法和不良信息举报中心|网上有害信息举报专区|962110 反电信诈骗|举报电话 021-62035905|Stage1st ( 沪ICP备13020230号-1|沪公网安备 31010702007642号 )

GMT+8, 2025-11-22 16:45 , Processed in 0.029673 second(s), 7 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表