Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css selectors query

Tags:

html

css

Here is a little piece of code.

<style ...>
h1 { color: red }
h2 { color: olive }
em { color: red }
h1 em { color: blue }
</style ...>

<body>
<H1>This <h2>headline is <EM>very</EM> important</h2> to me.</H1>
</body>

I even tried this code at jsfiddle, but couldn't understand WHY that last two words to me appear in black color. I thought it would be red.

like image 839
Rahul Utb Avatar asked Feb 28 '11 18:02

Rahul Utb


People also ask

What is CSS query selector?

The querySelector() is a method of the Element interface. The querySelector() method allows you to select the first element that matches one or more CSS selectors. The following illustrates the syntax of the querySelector() method: let element = parentNode.querySelector(selector); Code language: JavaScript (javascript)

What is query selector?

The querySelector() method in HTML is used to return the first element that matches a specified CSS selector(s) in the document. Note: The querySelector() method only returns the first element that matches the specified selectors. To return all the matches, use the querySelectorAll() method. Syntax: element.


1 Answers

That's because you cannot nest h1-h6 tags. The <h2> tag implicitly closes <h1> so it is interpreted as:

<body>
<H1>This </H1><h2>headline is <EM>very</EM> important</h2> to me.
</body>
like image 92
rsp Avatar answered Sep 30 '22 12:09

rsp