I have a text in index.html file inside "p" tag: Welcome to wonderful place
I need to add background-color:red to the word "wonderful". How I can do it only in css file without adding extra html tags and without js/jquery?
Asked
Active
Viewed 372 times
-2
-
Why can't you add extra tag? – Sato Takeru Mar 04 '21 at 13:45
-
1Without any way to tell the css which part to style that won't work. The best solution would just be to use a span tag. Is there a particular reason why you can't use other tags? – Josh Hales Mar 04 '21 at 13:46
-
2Apart from a couple of exceptions (things like first-letter, first-line), CSS can not access “parts of text” for individual formatting. CSS selects element nodes, not text nodes. There is perhaps a couple of ways you could try and “fake” this (like position a pseudo element behind the paragraph in the “correct” position), but those will be very rigid and inflexible, and not allow for much regular text flow/breaking at different widths. – CBroe Mar 04 '21 at 13:49
-
I need this specific behaviour only in one place, and according to task requirements I cannot change html file at all. Could you please share a piece of code on how to write a pseudo-element in this case, I tried to do it by myself, but nothing works – yakob Mar 04 '21 at 14:03
1 Answers
-1
you must add extra tags like span to style the particular word. wont matter much I guess

Rupak
- 529
- 6
- 16