Vishnu Shekhawat Vishnu Shekhawat - 4 months ago 25
CSS Question

css is not applied using this rule "element element". whats the issue in this code?

the CSS rule which says element element according to this link is not applied in below code . What's the issue in this ?

<!DOCTYPE html>
p div{
text-align: center;
color: red;

<h1 class="">This heading will not be affected</h1>
<p><div class="center">This paragraph will be red and center-aligned.</div></p>



It's not the rule, per se, it's the HTML, which is invalid. You can't wrap a <div> inside a <p>. Put the <p> inside the <div> and swap the rule to div p { and it will work.