html - Understanding working of `div` and `span` elements as children in Descendant selectors -


consider following code:

<!doctype html> <html> <head> <style> li p {     background-color: yellow; } </style> </head> <body>  <li>   <div>     <p>        usual text.     </p>   </div> </li> </body> </html> 

the usual text gets yellow background expected. if put block-level element <div> or <h2> inside <p> tags unusual happens. content between block-level elements , after block-level elements still inside <p> tags don't yellow background. e.g. consider following code,

<!doctype html> <html> <head> <style> li p {     background-color: yellow; } </style> </head> <body>  <li>   <div>     <p>        usual text<div>text inside div</div> after div inside p.     </p>   </div> </li> </body> </html> 

the problem doesn't appear if use inline-element <span> or <a> inside <p> tags.

  • why behavior shown block-level elements?

this has nothing css. purely html issue.

div elements not allowed inside p elements.

additionally, end tag p element optional , end of paragraph implied div start tag (rendering p end tag orphan).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -