Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use a heading tag inside a p tag and style it with CSS?

Tags:

html

css

Here is my code:

<html>
    <head>
        <style>
              div p h1 {
                  background-color: red;
              }
       </style>
    </head>
    <body>
        <div>
            <p><h1>hello2</h1></p> 
        </div>
    </body>
</html>
like image 305
Bisu Avatar asked Aug 11 '16 09:08

Bisu


1 Answers

I think thats why:

The <p> tag can only contain inline elements. The header tags are block-level elements, and cannot go inside <p> tags even when you style them to display inline.

like image 184
mtch9 Avatar answered Oct 12 '22 19:10

mtch9