Set CSS value in HTML to reflect current theme
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 35/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- css, javascript
研究方向
首先追蹤主題選擇器和 activateTheme() 函式,了解所選主題如何套用至頁面。向相關頁面容器新增可靠的深色模式標記,然後確認 SVG 樣式可以區分由選擇器選取的深色模式、淺色模式和瀏覽器偏好設定的深色模式。
由索引模型根據 Issue 內容生成。
描述
See this page, where the anchor points to an SVG. If you ensure that there's no theme in local storage for this page, then if the browser settings are used to switch between dark and light modes (I'm using Firefox), the SVG is styled appropriately to display correctly. However, if I use the theme selector on the page to select dark mode when the browser is set to light mode, the SVG does not display correctly.
The reason is that I style for light mode and use a media query to override some styles, using @media (prefers-color-scheme: dark). However, when the theme selector is used to select dark mode, then some dark-mode CSS is pulled in using the activateTheme() JS function, but from what I can tell this leaves no trace in the markup that we're now in dark mode. If there were e.g. a dark-theme class added to the <body> tag when the page is in dark mode, then I could duplicate the styling using an appropriate selector. My complete styling of the SVG is:
svg {
background-color: transparent !important;
}
line {
stroke: #000000;
fill: none;
stroke-opacity: 1;
}
polygon, rect {
fill: none;
stroke: #000000;
fill-opacity: 1;
stroke-opacity: 1;
}
polygon.filled {
fill: #ff0000;
}
polyline {
fill: none;
stroke-opacity: 1;
stroke: #000000;
}
text {
fill: #000000;
fill-opacity: 1;
stroke: none;
font-family: sans-serif;
font-style: normal;
font-weight: normal;
text-anchor: start;
}
@media (prefers-color-scheme: dark) { /* could duplicate this styling if body.dark-theme */
polygon, rect, polyline, line {
stroke: #ffffff;
}
text {
fill: #ffffff;
}
}
If there is another approach I could use to achieve the desired result (proper styling of the SVG in all cases), please let me know. Otherwise, would you consider adding dark-theme class to the body or other container tag so that I could try and achieve the desired result? Or have I missed somewhere where such a class has been added?
- 主要語言
- CSS
- 星號
- 90
- 分支
- 78
- 平均合併
- 2 天 19 小時
- 30 天內合併 PR
- 4
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/python-docs-theme 的其他 Issue
-
bug help wanted
難度 2/5 1-3 小時 新手友好度 68/100
python/python-docs-theme#289 · 7 則留言 · 2 個 reaction ·
-
難度 2/5 1-3 小時 新手友好度 68/100
python/python-docs-theme#217 · 7 則留言 · 1 個 reaction ·
-
難度 3/5 1-2 天 新手友好度 55/100
python/python-docs-theme#311 · 5 則留言 ·
-
enhancement github_actions
python/python-docs-theme#260 · 6 則留言 · 已指派 1 人 ·
-
難度 4/5 3-5 天 新手友好度 35/100
python/python-docs-theme#245 · 3 則留言 ·
查看 python/python-docs-theme 的全部 Issue
相似的 Issue
-
Add: hunch 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
AbdelStark/awesome-typesafe#104 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
-
A11y ♿️
難度 2/5 1-3 小時 新手友好度 72/100
-
automated issue report
難度 2/5 1-3 小時 新手友好度 85/100
-
documentation improve or update documentation priority/low triage
難度 2/5 半天 新手友好度 86/100
warpdotdev/docs#782 · 1 則留言 ·