How to handle background color of text using css, how to control or mange width of background color | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to handle background color of text using css, how to control or mange width of background color

If we use <p style="background-color: aqua"> please solve my query</p> This line change background color of text as well as it will change whole line, i want to change only text background color.

29th Dec 2022, 4:50 PM
WarLord
WarLord - avatar
25 Answers
+ 2
Yeah got it we can use span
29th Dec 2022, 6:06 PM
WarLord
WarLord - avatar
+ 7
This will solve your issue. Write this in css: p{ background-color:red; width:auto; display:inline-block ; }
29th Dec 2022, 6:56 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
<p style= "background-color: aqua; color:red"> back ground in aqua, text in red..? </p> <p style="color:aqua"> only text in color aqua ..? </p>
29th Dec 2022, 5:52 PM
Jayakrishna 🇮🇳
+ 2
you can leave tag empty with colored background and use before or after pseudo-element. HTML: <p class="prgh" style="background-color: white"/> CSS: .prgh::after{ content:"text"; background-color: aqua } if you want easier: maybe you will be able to do this in css4 :)) but in the current version, as I know, you can't.
29th Dec 2022, 5:21 PM
Foad Mohtadi
Foad Mohtadi - avatar
+ 2
<p style="color:aqua"> only text in color aqua ..? </p>
29th Dec 2022, 5:58 PM
Jayakrishna 🇮🇳
+ 1
WarLord like this? <p><span style= "background-color: aqua; color:red"> back ground in aqua, text in red..? </span></p>
29th Dec 2022, 6:02 PM
Jayakrishna 🇮🇳
+ 1
Great thank you so much
29th Dec 2022, 7:08 PM
WarLord
WarLord - avatar
+ 1
WarLord you can also create your own custom tags https://code.sololearn.com/WHTwvuP4EOJP/?ref=app
29th Dec 2022, 10:18 PM
Bob_Li
Bob_Li - avatar
+ 1
To change the background color of the text only, you can use the background-color property in conjunction with the display property set to inline-block. For example: p { display: inline-block; background-color: aqua; }
31st Dec 2022, 5:56 AM
Payal Manghnani
Payal Manghnani - avatar
+ 1
Finally we have four ways to do that
31st Dec 2022, 6:48 AM
WarLord
WarLord - avatar
+ 1
It's set default, if you want increase or decrease by using Width ,height,background-size,etc
31st Dec 2022, 11:30 AM
GANIREDDY NUTHANA VARA PRADEEP
GANIREDDY NUTHANA VARA PRADEEP - avatar
0
Your p tag whole paragraph text background colour will be aqua You need to set the height width of div and inside div write the same paragraph tag and give div border colour
29th Dec 2022, 5:14 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Hi, You can put your code in a parent div and set the p tag width to 'max-content' (if needed??). The code will like this. <div style="background-color: white"> <span style="background-color: aqua">your text...</span> </div> Have fun!
29th Dec 2022, 5:14 PM
Foad Mohtadi
Foad Mohtadi - avatar
0
No thats the problem i just want a single line of paragraph
29th Dec 2022, 5:15 PM
WarLord
WarLord - avatar
0
If you have multiple paragraph tag then you can assign a class or I'd to specific element and apply css
29th Dec 2022, 5:16 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
I said single line of paragraph and want to background color of text only not whole line
29th Dec 2022, 5:17 PM
WarLord
WarLord - avatar
0
Ok
29th Dec 2022, 5:23 PM
WarLord
WarLord - avatar
0
So in css , we have to write again line that we wrote in paragraph into content
29th Dec 2022, 5:28 PM
WarLord
WarLord - avatar
0
Still background color will be whole line requirement is the background color must be only on text background color not whole line
29th Dec 2022, 5:57 PM
WarLord
WarLord - avatar
0
Read properly need background of text is colourd and means if i wrote i like coding background of that word only should we in colour not whole line
29th Dec 2022, 6:02 PM
WarLord
WarLord - avatar