-2

I show data with custom text color and how can I set background color with Javascript / alpinejs 2.2 to be text always good visible?

Thanks!

Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91
  • 1
    Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output using the `[<>]` snippet editor. – mplungjan Aug 25 '20 at 13:52
  • Depending on your text color, "good visible" background color can be almost everything. What is your text color? – njank Aug 25 '20 at 13:53
  • Perhaps use some of these ideas: https://www.google.com/search?q=css+color+contrast – mplungjan Aug 25 '20 at 13:54

1 Answers1

1

Using Alpine.js you can bind the style attribute:

<div x-data="{ background: '#333' }" x-bind:style="`background-color: ${background}`">Dark grey background container</div>
Hugo
  • 3,500
  • 1
  • 14
  • 28