How to apply style to an element from the value of the same using CSS

Asked

Viewed 27 times

0

Good afternoon, I would like to know if there is a possibility to apply style to an element from its value. for example...

<p>Ola mundo</p>


p(mundo){

  background-color('blue')

}

in case the whole paragraph would be blue background color.

Is there such a possibility?

  • I don’t know if I understand your idea, but if you want to change the style of the specific paragraph "Hello world", just do <p style="background-color:blue;">Ola mundo</p>

  • Unfortunately it cannot be so, because I will assign this color dynamically if there is the world for example...

1 answer

1


All I know is a way to do something similar, and yet I’d need to have the same tag text on one dataset, ai yes you could use a CSS selector by Attribute to pick up the text.

Here is an example, note that the first and last line have the text "blue", inside the tag <p> and tb in the data-text, with that I use the p[data-text*="blue" i] to catch any mention of the text blue (*), high-cash independent (i), and use as selector to apply the blue color.

p[data-text*="blue" i]{
  color: blue;
}
<p data-text="Lorem ipsum dolor blue sit amet.">
  Lorem ipsum dolor blue sit amet.
</p>
<p data-text="Lorem, ipsum dolor.">
  Lorem, ipsum dolor.
</p>
<p data-text="Lorem ipsum dolor sit amet BLUE consectetur adipisicing elit. Id, nobis.">
  Lorem ipsum dolor sit amet BLUE consectetur adipisicing elit. Id, nobis.
</p>

In short, if you have the floor blue, within the text of data-text, will apply the blue color to tag <p>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.