Skip to content
Advertisement

Apply two different colors as a gradient to different words in element

I’m trying to render the fizz buzz function in an unordered list, with each word corresponding to a different color (‘fizz’– green, ‘buzz’–blue) like so:

fizz buzz

I’m successfully rendering “fizz” and “buzz” in their colors on their own, but when it comes to rendering the “fizzbuzz” line, the entire background of the <li> is split between green and blue instead of only the individual words.

Here’s the css selector responsible for “fizzbuzz”:

JavaScript

I tried modifying the display property on the parent <ul> to “inline” but that doesn’t fix the problem:

JavaScript

I’m trying to do this in pure css without modifying my html/js. Here’s the code:

JavaScript
JavaScript
JavaScript

Any help would be appreciated.

Advertisement

Answer

add width:fit-content;

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement