/* CSS */
em {font-style: italic; background yellow}
::autonomous-not-child-of-a-p-element-? :: em {font-style:normal; background gray}
Given two situations both using <em>
differently, in need to be styled differently.
The first case contains a paragraph element and within it one or multiple <em>
italic styled words:
<p>...</p>
<p>A paragraph with a <em>word or two</em> in italic emphasis within the paragraph.</p>
<p>...</p>
The second paragraph contains a <em>
wrapping over an entire paragraph, becoming itself a paragraph, that needs to be styled differently:
<p>...</p>
<em>An entire paragraph in its entirety in italic emphasis.<em>
<p>...</p>
Is there a way to restyle the last <em>
differently automatically, when it spans an entire paragraph and is not a child of a <p>
element?
5
Answers
You can use hierarchy/inheritance in css to target the em in p tag and normal em element to target the em tag.
Also, this can be helpful to understand.
Hope, this helps.
refer:
https://www.w3schools.com/cssref/sel_element_pluss.php
in order to solve this issue. You can simply use the
not
selector to select everyem
element not a child of ap
element.If you have issues with this answer or if I didn’t totally answered it, let me know !
So if you have only these two conditions then you can try this solution
Solution
This will target only the child of p tag
p>em {
color: #ff0000;
font-size:30px;
}
If em is below
tag then this code will target every em that is below
tag
p+em {
color: #ff0000;
font-size:30px;
}