list three ways to select html elements in css code example

Example 1: css selectors

* {
color: pink;
}
h1, h2 {Select all h1 and h2}
li a {select all anchor inside a list}
h1 + p {select all p placed after an h1}
div > li {all li directly in a div}

Example 2: what is css selector

div { color: red; } // the "div" in .css is a selector targeting all <div> elements
simpleSelector = document.querySelectorAll()("div"); // all divs 
complexSelector = document.querySelector("div.user-panel.main input[name='login']")  // the first <input> element with the name "login" (<input name="login"/>) located inside a <div> whose class is "user-panel main" (<div class="user-panel main">) in the document is returned

Tags:

Html Example