Reputation: 57
I have a div class called index and inside that, I have two more div without class or id name and two <p>
tags. I want to apply the style for these two <p>
tags.
<div class="doubt">
<div>
<p>Hello world</p>
<div>
<p>Hello</p>
</div>
</div>
</div>
How to apply different style for two p tags?
Please help me out from this, Thanks in Advance!
Upvotes: 3
Views: 9662
Reputation: 546
You can use inline styling.
<div class="doubt">
<div>
<p style="color: yellow">Hello world</p>
<div>
<p style="color: red">Hello</p>
</div>
</div>
</div>
as well you you can use hierarchical structure in style to apply styling on these paragraphs.
<head>
<style>
.doubt div p{
color: red;
}
.doubt div div p{
color: green;
}
</style>
</head>
<body>
<div class="doubt">
<div>
<p>Hello world</p>
<div>
<p>Hello</p>
</div>
</div>
</div>
</body>
hope this will help you.
Upvotes: 1
Reputation: 11
You can also use inline sytling.
<div class="doubt">
<div>
<p style="color: red">Hello world</p>
<div>
<p style="color: green">Hello</p>
</div>
</div>
</div>
Upvotes: 0
Reputation: 917
Simple Just use this css
Let me know any further clearification.
.doubt > div > div > p {
color: green;
}
.doubt > div > p {
color: red;
}
<div class="doubt">
<div>
<p>Hello world</p>
<div>
<p>Hello</p>
</div>
</div>
</div>
Upvotes: 3
Reputation: 3785
You can apply different style for two p
tags like below:-
.doubt div:nth-child(1) p{ color:green;}
.doubt div:nth-child(2) p{ color:red;}
<div class="doubt">
<div>
<p>Hello world</p>
<div>
<p>Hello</p>
</div>
</div>
</div>
Upvotes: 0