4

I have a <div> element with a <p> element inside:

<div style="font-size:10pt; color:red;">
    This is my Parent Div.
    <p>This is my Child Paragraph.</p>
    My parent Div Ends Here.
</div>

How can I prevent my paragraph from inheriting the CSS properties set to the <div>?

0

3 Answers 3

1

In your case the best way is to just over right the styles that the <p> element is inheriting:

So in your CSS file, which you should be using instead of inline styles:

.parent-div {
    font-size: 10pt;
    color: red;
}

.child-paragraph {
    font-size: 12pt;
    color: black;
}
Sign up to request clarification or add additional context in comments.

Comments

0

In your child node -

<p style="font-size:12pt; color:black;">This is my child</p>

Just set the inline style to whatever you want.

1 Comment

This will be possible only when very few styles are set. Currently my Focus Node is Paragraph and i will be having different parent Nodes. So i want to avoid the styling of all Parent Nodes and Keep whatever i have set to my Paragraph.
0

You can use the > selector in CSS to select the immediate child p of div.

Fiddle link

div > p {
    font-size:1.2 em;
    color: green;
}

3 Comments

is there any way to make all the styling to default value. As you said paragraph styling we can set.But all values i want to set to the default.How can i set that.
What do you mean by all values? Please elaborate a little?
All CSS style informations like backgroundColor, image etc... Currently i am making a class and with all style information adn trying to add that class to the required location

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.