无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 109|回复: 2
打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
1#
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. }
复制代码



2#
发表于 2 小时前 | 只看该作者
感谢分享!
回复

使用道具 举报

3#
发表于 半小时前 | 只看该作者
  • 文字压底边通过 line-height: 28px; 实现(比 height: 26px 高 2px),让文字略微下沉到底部。
  • 如果你以后想改成 垂直居中顶部对齐,只需要修改 line-height 和 padding 即可。

以下代码,供参考
  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 */
  63. .tab:before, .tab:after,
  64. .tab2:before, .tab2:after,
  65. .tab3:before, .tab3:after {
  66.   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");
  67. }

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

  77. /* 悬停时的梯形 SVG */
  78. .tab:hover:before, .tab:hover:after,
  79. .tab2:hover:before, .tab2:hover:after,
  80. .tab3:hover:before, .tab3:hover:after {
  81.   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");
  82. }

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

  93. /* 当前页的梯形 SVG */
  94. .activetab:before, .activetab:after {
  95.   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");
  96. }
复制代码




回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2025-11-21 19:47

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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