아래 구분선으로 구분된 두 코드는 웹페이지에 존재하는 거의 모든 “상단 바(헤더‧네비바‧Top-bar 등)”를 #2F4F2F(딥 그린)으로 바꾸는 코드야. 실리콘밸리 css 전문가의 입장에서, 두 코드의 실효성에 대해 점수를 매기고, 두 코드에서 얻은 교훈을 바탕으로 최상의 css 코드를 제공해 줘.
/* ==UserStyle==
@name Universal Deep-Green Topbars
@description Force-paint every top bar (fixed/sticky/header/navbar…) dark-green
@version 1.0.0
@namespace https://github.com/yourname/userstyles
@match :///*
==/UserStyle== */
/* ■■■ 1) 색상 변수 – 바꾸고 싶으면 여기만 고치세요 ■■■ /
:root{
--topbar-bg : #2F4F2F; / 배경색 (딥 그린) /
--topbar-fg : #ffffff; / 글자·아이콘 색 (화이트) */
}
/* ■■■ 2) ‘위에 붙어있는 바’를 최대한 넓게 포착 ■■■ /
/ 2-A) position 이 fixed 또는 sticky 이면서 top:0 인 경우 /
[style="position:fixed"][style*="top:0"],
[style*="position:sticky"][style*="top:0"],
.fixed.top-0, /* Tailwind 패턴 */
.sticky.top-0,
.top-0.fixed,
.top-0.sticky,
/* 2-B) · 태그 (대부분 사이트에서 상단바 역할) */
header,
nav,
/* 2-C) 네이밍 컨벤션(클래스/ID 속성명에 header·navbar·topbar …가 포함) /
[class="header"],
[id*="header"],
[class*="navbar"],
[id*="navbar"],
[class*="topbar"],
[id*="topbar"],
[class*="top-bar"],
[id*="top-bar"],
[class*="appbar"],
[id*="appbar"],
[class*="site-header"],
[id*="site-header"],
[class*="main-header"],
[id*="main-header"],
[role="banner"]
{
background-color: var(--topbar-bg) !important;
color : var(--topbar-fg) !important;
fill : var(--topbar-fg) !important; /* SVG 아이콘 /
stroke : var(--topbar-fg) !important;
border-color : var(--topbar-bg) !important; / 투명 or 같은색으로 맞춤 */
/* 투명도·그라디언트 등 기존 배경을 억제 */
background-image : none !important;
background-color : var(--topbar-bg) !important;
}
/* ■■■ 3) 상단바 안쪽 자식 요소들도 글자/아이콘 색 통일 ■■■ */
header *, nav ,
[class="header"] , [id="header"] ,
[class="navbar"] , [id="navbar"] ,
[class="topbar"] , [id="topbar"] *,
[role="banner"] *
{
color : var(--topbar-fg) !important;
fill : var(--topbar-fg) !important;
stroke : var(--topbar-fg) !important;
}
/* ■■■ 4) z-index 보정 : 어떤 사이트는 상단바가 내용 밑으로 들어가기도 함 ■■■ /
header, nav,
[class="header"], [id*="header"],
[class*="navbar"], [id*="navbar"],
[class*="topbar"], [id*="topbar"],
[role="banner"]
{
z-index: 9999 !important;
}
/* 최대한 포괄적인 상단 바 스타일 - Edge + Stylus용 */
/* 1. 위치 기반 - sticky/fixed 요소들 */
[class="sticky"],
[class="fixed"],
.sticky,
.fixed,
[style="position: sticky"],
[style="position: fixed"] {
background-color: #2F4F2F !important;
}
/* 2. 의미론적 태그 */
header,
nav,
*[role="banner"],
*[role="navigation"] {
background-color: #2F4F2F !important;
}
/* 3. 클래스명 패턴 기반 */
[class="header"],
[class="Header"],
[class="navbar"],
[class="nav-bar"],
[class="navigation"],
[class="topbar"],
[class="top-bar"],
[class="menubar"],
[class="menu-bar"],
[class="toolbar"],
[class="app-bar"],
[class="appbar"] {
background-color: #2F4F2F !important;
}
/* 4. 상단 위치 기반 */
[class="top-0"],
[class="top:0"],
[style="top: 0"],
[style="top:0"] {
background-color: #2F4F2F !important;
}
/* 5. z-index 높은 요소들 (보통 상단 바가 높은 z-index를 가짐) */
[style="z-index: 9"],
[style="z-index:9"],
[class="z-50"],
[class="z-40"],
[class="z-30"] {
background-color: #2F4F2F !important;
}
/* 6. 배경색이 있는 상단 요소들 */
[class="bg-"],
[style="background"] {
background-color: #2F4F2F !important;
}
/* 7. 레이아웃 기반 추가 /
[class="flex"][class="justify"],
[class="flex"][class*="items"] {
background-color: #2F4F2F !important;
}
/* 8. 특정 높이를 가진 요소들 */
[class="h-12"],
[class="h-16"],
[class="h-20"],
[style="height: 48px"],
[style="height: 64px"],
[style="height: 72px"],
[style="height: 80px"] {
background-color: #2F4F2F !important;
}