+ 5

Html and css

I want to change only second p tag color is yellow....What is the internal style css code for <div class="u"> <p>Hii</p> <p>Hello</p> </div> Without add any span tag and id tag inside that code...????????????

24th Jun 2020, 4:31 AM
Cheliyan
Cheliyan - avatar
7 Réponses
+ 3
You can give classname to the p tag which you want to be yellow and use p.class_name in css or you can do it by style attribute in particular p tag. For example. <p style="color:yellow">Hello</p> Or p. class_name { color:yellow; }
24th Jun 2020, 5:16 AM
Darshan R
Darshan R - avatar
+ 2
#u p:nth-child(2) { color:yellow; } You can go this way.. or either div has only two p tags so #u p:last-child{ color:yellow; }
24th Jun 2020, 5:17 AM
Nikhil Maroju
Nikhil Maroju - avatar
+ 2
the most specific selector we could write giving your code sample is: div.u > p:nth-child(2) { color: yellow; /* or background-color, depending on your needs ^^ */ } ...but you need to be more specific (impossible to guess without the parent structure of your snippet) if you have another <div class="u"> elsewhere in your code with a <p> direct 2nd child of it and you don't want to target it ;) instead of 'nth-child' selector you could use 'nth-of-type', but that will not avoid conflicts with other possible target: in such case being more specific requires maybe to give the full path from the <body> element... ie: body > div.myclassusedinmanydiv:nth-child(x) > div.u:nth-child(y) > p:nth-child(2)
24th Jun 2020, 5:32 AM
visph
visph - avatar
0
Add a class to ur 2nd p and define the class differently or use inline css<p style="">hello</p>
24th Jun 2020, 11:02 AM
TheAdeyemiOlayinka 💗
TheAdeyemiOlayinka 💗 - avatar
0
div:nth-child(2){ // your code goes here }
25th Jun 2020, 3:56 PM
AHMAD AMIRU
AHMAD AMIRU - avatar
0
https://t.me/Coders_Crafters join our Teligram group for discussion about HTML 5 & CSS codes questions and many more
13th Oct 2023, 4:05 AM
Alison Pinto
Alison Pinto - avatar
- 1
Just add class to your paragraph. <p class="style"> and then in css do .style{color:yellow;}
24th Jun 2020, 9:03 PM
NiveaShampon
NiveaShampon - avatar