婆罗门
精华
|
战斗力 鹅
|
回帖 0
注册时间 2019-11-28
|
帮你问了Gemini3:
这是一个非常经典的“Chrome风格”CSS修改需求。要达到你图片中的效果,核心难点在于:
- SVG 变色:原本的代码只处理了白色和悬停色,我们需要给“非当前页”也加上带有颜色的 SVG 梯形背景。
- 层级关系:当前页必须覆盖在非当前页之上。
- 去除边框/凸起:需要强制重置 Tablacus 默认的一些边框样式。
以下是为您修改完善后的代码。我已经为您调好了配色(参考了您的理想样式图),并添加了详细注释方便您后续微调颜色。
完整的 CSS 代码
请复制并替换原本的所有 CSS 内容:
- /* ==========================================================================
- 基础设置与颜色定义
- ========================================================================== */
- /* 1. 去除默认的边框、阴影和凸起效果 */
- .tab, .tab2, .tab3, .activetab,
- .tab:hover, .tab2:hover, .tab3:hover {
- box-shadow: none !important;
- border: none !important;
- outline: none !important;
- }
- /* 2. 标签栏整体背景 (对应您图中的“颜色4”) */
- .tab0 {
- /* 这里设置标签栏底色,建议使用深蓝灰色 */
- background-color: #648ca5;
- padding: 5px 0 0 5px; /* 顶部留点空隙,左侧留空隙 */
- height: 30px; /* 强制高度,防止布局乱跳 */
- }
- /* ==========================================================================
- 标签通用形状 (所有标签都生效的样式)
- ========================================================================== */
- .tab, .tab2, .tab3, .activetab {
- position: relative;
- display: inline-block;
- height: 26px; /* 标签高度 */
- line-height: 28px; /* 文字垂直居中微调 */
- padding: 0 15px; /* 文字左右间距 */
- margin: 0 8px; /* 标签之间的重叠/间距,负数可以让它们重叠 */
- font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
- cursor: default;
- vertical-align: bottom; /* 底部对齐 */
- }
- /* 通用的伪元素设置 (用于显示梯形两侧) */
- .tab:before, .tab:after,
- .tab2:before, .tab2:after,
- .tab3:before, .tab3:after,
- .activetab:before, .activetab:after {
- content: "";
- position: absolute;
- bottom: 0;
- width: 25px; /* SVG图片的宽度 */
- height: 26px; /* 必须与标签高度一致 */
- pointer-events: none; /* 防止鼠标点到圆角上没反应 */
- }
- /* 左侧圆角位置 */
- .tab:before, .tab2:before, .tab3:before, .activetab:before {
- left: -18px; /* 根据SVG宽度调整,负值 */
- }
- /* 右侧圆角位置 (镜像翻转) */
- .tab:after, .tab2:after, .tab3:after, .activetab:after {
- right: -18px;
- transform: scaleX(-1);
- }
- /* ==========================================================================
- 状态 A: 非当前页 (普通标签) - 对应“颜色2”
- ========================================================================== */
- .tab, .tab2, .tab3 {
- /* 非当前页背景色 (稍浅于底色,或灰色) */
- background-color: #8daabb;
- color: #eee; /* 非当前页文字颜色 */
- z-index: 1; /* 层级低,被当前页压住 */
- }
- /* 非当前页的梯形 SVG (填充色必须对应上面的 background-color: #8daabb) */
- .tab:before, .tab:after,
- .tab2:before, .tab2:after,
- .tab3:before, .tab3:after {
- /* 下方 fill=%238daabb 就是颜色代码,如果改背景色,这里也要改 */
- 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");
- }
- /* ==========================================================================
- 状态 B: 鼠标悬停 (Hover) - 对应“颜色3”
- ========================================================================== */
- .tab:hover, .tab2:hover, .tab3:hover {
- /* 悬停时的背景色 (浅蓝色) */
- background-color: #bfe0f0;
- color: #000;
- z-index: 5; /* 悬停时层级提高 */
- }
- /* 悬停时的梯形 SVG (填充色 fill=%23bfe0f0) */
- .tab:hover:before, .tab:hover:after,
- .tab2:hover:before, .tab2:hover:after,
- .tab3:hover:before, .tab3:hover:after {
- 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");
- }
- /* ==========================================================================
- 状态 C: 当前页 (Active) - 对应“颜色1”
- ========================================================================== */
- .activetab {
- /* 当前页背景色 (白色) */
- background-color: #ffffff;
- color: #000; /* 当前页文字颜色 */
- z-index: 10; /* 层级最高,压在所有标签上面 */
- font-weight: bold;
- }
- /* 当前页的梯形 SVG (填充色 fill=%23ffffff) */
- .activetab:before, .activetab:after {
- 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");
- }
复制代码
代码修改说明 (DIY指南)
如果需要自己修改颜色,请注意以下几点:
- 颜色同步: 由于使用了 SVG 制作梯形圆角,CSS 背景色 (background-color) 必须和 SVG 图片代码里的 fill 颜色一致,否则会出现中间是颜色A,两边耳朵是颜色B的情况。
- 如何修改 SVG 颜色: 代码中 url("data:image/svg+xml... fill%3D%22%23xxxxxx%22 ...") 这一长串里,%23 代表 # 号,后面的 6 位字符就是颜色代码。
- 例子:如果您想把“非当前页”改成灰色 (#cccccc):
- 修改 .tab { background-color: #cccccc; }
- 找到“非当前页 SVG”那段,把 fill%3D%22%238daabb%22 改成 fill%3D%22%23cccccc%22。
- 去除凸起条: 我在代码最上方使用了 border: none !important;,这会强制去除 Tablacus 有时会自动给 Active Tab 顶部加的一条高亮线。
- 高度调整: 现在的代码设定标签高度为 26px。如果您觉得太矮或太高,需要同时修改 .tab 的 height 和 svg 中的 height 属性,比较麻烦。目前的 26px 是比较接近 Chrome 经典样式的比例。
|
评分
-
查看全部评分
|