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.
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)
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With