How to use the style tag in part of a text?

Asked

Viewed 330 times

-1

I want to do something kind of like this:

<p style="color:red;">Esse texto é vermelho e <style="color:blue;">esse texto é azul</style> mas esse outro continua vermelho</p>

I think you have understood. I want to take an excerpt of the text and change only the color of a few words, but the rest remains the same.

2 answers

4


You can use the tag <span></span>

<p style="color:red;">Esse texto é vermelho e <span style="color:blue;">esse texto é azul</span> mas esse outro continua vermelho</p>

the tag <style></style> is to insert CSS and not a tag tag

<p style="color:red;">Esse texto é vermelho e <span style="color:blue;">esse texto é azul</span> mas esse outro continua vermelho</p>

  • 1

    The tag markis not used to change the color of a text. The function of the tag is to highlight a text snippet as if it were a text marker.

  • Yes, it serves as a text tag. So I edited and quoted the span tag tbm and put the background: None some previous versions of Chrome/Firefox had no default background and was left with nothing. but I edited and tagged span

  • It is because it is an HTML5 tag that does not work in some older versions of browsers.

  • 1

    @sam, with the tag <tiosam></tiosam> works, see my answer

  • @Leocaracciolo <vovô></vovô> tb works in browsers of the 90s.

  • @sam edited the answer

Show 1 more comment

2

You can use custom tag.

<p style="color:red;">Esse texto é vermelho e <tiosam style="color:blue;">esse texto é azul</tiosam> mas esse outro continua vermelho</p>

If your PC is from the 90s use the tag vovô

<p style="color:red;">Esse texto é vermelho e <vovô style="color:blue;">esse texto é azul</vovô> mas esse outro continua vermelho</p>

Just remembering that, besides this comment have been IMPORTED, it is worth remembering also that custom elements are still in adoption, and to ensure that they are valid is the case to follow the specification. In principle, they work based on browser tolerance. More details: Custom elements

Living Standard - Last Updated 19 September 2018 - 4.13 Custom Elements

  • 1

    Does it have to do with semantics? rs

  • 1

    @sam, the tags grandpa and uncle do chongas but accept style

  • https://answall.com/questions/134816/cria-as-pr%C3%b3prias-tags-affects-something#comment279355_134816

  • 2

    Just remembering that custom elements are still in adoption, and to ensure they are valid is the case to follow the specification. In principle, they operate based on browser tolerance. More details: https://www.w3.org/TR/custom-elements/

Browser other questions tagged

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