sabberworm / PHP-CSS-Parser

A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS

Home Page:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CSS rgb and rgba functions can't accept custom property

thomashigginbotham opened this issue · comments

The following CSS results in the parser stripping the value.

:root {
  --my-color: 255, 0, 0;

body {
  color: rgb(var(--my-color));

It seems that the parser thinks the value is invalid since rgb expects three arguments and is only receiving one. However, the CSS works correctly in every major browser.

The reason I am using this syntax is because I'm passing the --my-color variable to various rgba functions throughout the style sheet, and while the color might change, the alpha value of each rgba function is defined separately. I.e., I can't set --my-color to rgba(255, 0, 0, .5) as I'd require hundreds of variables for each opacity.

Actually, it appears that any custom property passed as an argument to rgb or rgba results in the value being removed. For example:

body {
  color: rgb(var(--color-red), var(--color-green), var(--color-blue));

results in body{}

I believe this is a duplicate of #186.

I noticed that NitroPack:fix/css4-rgb-parsing corrects this bug (at least for my use case). Is it possible to merge it?

Never mind. I was using the latest release of PHP-CSS-Parser (8.3.1), and this issue seems to be resolved on the master branch.

I did run into another problem where the calc() function is not allowed within the rgba() function. I submitted a PR that resolves that issue.

ezoic increase your site revenue