Vishnu Shekhawat Vishnu Shekhawat - 1 year ago 66
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>


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download