Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to apply css to a <p> tag

Tags:

html

css

styles

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!

like image 845
nataraj sarath Avatar asked Nov 22 '25 21:11

nataraj sarath


2 Answers

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>
like image 154
jaydeep patel Avatar answered Nov 25 '25 10:11

jaydeep patel


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.

like image 38
Safwan Shaikh Avatar answered Nov 25 '25 10:11

Safwan Shaikh