惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
J
Java Code Geeks
V
V2EX
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
博客园 - Franky
爱范儿
爱范儿
T
Tailwind CSS Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
博客园_首页
B
Blog RSS Feed
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Danb Blog

August 2026: What I've Been Working On · Danb Blog Great Tech: Intel 2500k CPU · Danb Blog July 2026: What I've Been Working On · Danb Blog My Experience with Ubuntu Desktop 26.04 · Danb Blog Thumbnails for Orca 3MF in GNOME Files · Danb Blog Cheaper Sodastream Gas with a Big Tank · Danb Blog June 2026: What I've Been Working On · Danb Blog Running Snyk On Forgejo/Codeberg Actions · Danb Blog Tuta & Proton: An Open Source Client Does Not Result in an Open Source Service · Danb Blog May 2026: What I've Been Working On · Danb Blog 3D Printing Parts for my Greenhouse, Round 2 · Danb Blog Great Devices: Nexus 7 2013 · Danb Blog R36S Console RetroArch Stuck Menu Issue · Danb Blog April 2026: What I've Been Working On · Danb Blog Basic OpenCode Sandboxing with Docker · Danb Blog Games Played in 2025 · Danb Blog March 2026: What I've Been Working On · Danb Blog Shivam Mathur's "node-docker" Images are Awesome for PHP CI · Danb Blog February 2026: What I've Been Working On · Danb Blog Your BookStackApp project was assigned as a project for my Software Architecture course · Danb Blog My Sovol SV08 3D Printer Setup in 2026 · Danb Blog January 2026: What I've Been Working On · Danb Blog Epson Printer: The administrator password you entered was not recognized · Danb Blog Pressure to Follow Process · Danb Blog Online Shopping Email Notifications · Danb Blog My HomeLab Setup in 2026 · Danb Blog Linux Label Printing with the Phomemo D30 · Danb Blog Reporting to the CMA: Google Android Developer Verification · Danb Blog OPNsense & Dnsmasq: Responding with specific DNS servers · Danb Blog An Impromptu Introduction to ZFS Drive Replacement at 1am · Danb Blog
The Power of currentColor · Danb Blog
2020-10-17 · via Danb Blog

Within BookStack I wanted to allow customizability of the theme colors in a few cases. These are often applied to things like buttons or links, an element may utilise that theme color in a few different shades.

My first thought was to dynamically generate out the CSS styles for such elements, so the custom color could be added to the page. This meant maintaining a set of color-specific styles outside of the core CSS so wasn't ideal. Then I learnt of currentColor.

currentColor is a valid CSS color value which will refer to the text color of the current element. It's well supported, down to IE9. Using this you could set borders, shadows, backgrounds, or anything that takes a color value, to use the current text color of the element.

Below is an example of a themed button. Only a single color is set on this element, found inline, otherwise the border color, SVG icon fill color & background color all make use of currentColor. The color picker will auto-change the single text-color CSS on the element, nothing else, but everything will match thanks to currentColor!

Using this approach, you wouldn't need to have different button styles defined in your CSS for different colors, you could make a generic currentColor button then apply colors using some text-color utility classes. If targeting modern browsers then CSS variables are an alternative solution, depending on use-case. You could even combine those options, using CSS variables to set the main text color then use currentColor to syle related components of the element.

Demo

Change Color:

Demo CSS

#example-button {
    color: #4f53bf;
    border: 2px solid currentColor;
    padding: .5rem 1rem;
    background-color: transparent;
    font-weight: bold;
    position: relative;
}
#example-button::before {
    background-color: currentColor;
    position: absolute;
    content: '';
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.15;
}
#example-button svg {
    fill: currentColor;
}