Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting Colour from HTML Element

I’m trying to create a re-usable component on my Blazor Application, that allows another developer to input one colour (for the background), and then colour when rendering the component will calculate the text and other colours that are needed for the component. At the moment, I can input the Background Colour, but then I can’t find out how to convert the colour (string format) to a HSL to use any Css calc() tricks on.

/// <summary>
/// Define the colour of the card. It can accept any string value. The default is #DEF4F58C Hexadecimal.
/// </summary>
[Parameter] public string BackgroundColour { get; set; } = "#DEF4F58C";

This is the parameter that is passed, but I need help understanding how to get this colour into a HSL format for reusability.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can apply HEX to HSL transformation, described for JS here Alternatively, you can use a NuGet like this one: ColorHelper

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading