Skip to content

CSS rgb and rgba functions can't accept custom property #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thomashigginbotham opened this issue Jun 8, 2021 · 4 comments
Closed

CSS rgb and rgba functions can't accept custom property #257

thomashigginbotham opened this issue Jun 8, 2021 · 4 comments

Comments

@thomashigginbotham
Copy link

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.

@thomashigginbotham
Copy link
Author

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{}

@westonruter
Copy link
Contributor

I believe this is a duplicate of #186.

@thomashigginbotham
Copy link
Author

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

@thomashigginbotham
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants