1

<span style="color: #21584b;"><p>Text</p></span>

That's an example of some code I have in my website. The colour is a dark green and it displays normally on my PC as well as on my Android phone. But, when viewed on an iPhone or an iMac the text is within the <p> tag appears white. I don't have any CSS in the stylesheet targeting just a <p> or a <span>. All of the CSS in the stylesheet has an additional class or an id.

I've removed the <span> tags wrapping the <p> one, but I have no way of testing it since I don't own any Apple devices myself.

So, the question is, will elements inherit inline CSS, like I've put here if they don't have any classes or ids overriding them?

1
  • 5
    <p> is not a valid child of <span> so chances are some browsers are "correcting" your invalid HTML and the result is not what you expect. Commented Feb 26, 2018 at 12:49

2 Answers 2

2

Do it the other way round (span inside p), that's valid HTML and will overrule any previous properties for p:

<p><span style="color: #21584b;">Text</span></p>
Sign up to request clarification or add additional context in comments.

Comments

2

Yes. If the value of a property is inherit then it will copy the value from the parent element regardless of how it was applied to the parent element.


That said, a <p> may not be a child element of a <span> element. The differences you are experiencing are likely due to different browsers recovering from your invalid HTML in different ways.

1 Comment

And it likely has to do with the surrounding markup that's not shown, too - <!DOCTYPE html><body><span ...><p>...</p></span></body> behaves identically in all browsers, whereas a more complex layout is likely to be less than interoperable.

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.