/* Selects all elements */
* {
color: green;
}
/* All <a> elements. */
a {
color: red;
}
/* All elements with class="spacious" */
.spacious {
margin: 2em;
}
/* All <li> elements with class="spacious" */
li.spacious {
margin: 2em;
}
/* All <li> elements with a class list that includes both "spacious" and "elegant" */
/* For example, class="elegant retro spacious" */
li.spacious.elegant {
margin: 2em;
}
/* id="demo" 요소 선택 */
#demo {
border: red 2px solid;
}
/* <a> elements with a title attribute */
a[title] {
color: purple;
}
/* <a> elements with an href matching "https://example.org" */
a[href="https://example.org"]
{
color: green;
}
/* <a> elements with an href containing "example" */
a[href*="example"] {
font-size: 2em;
}
/* <a> elements with an href ending ".org" */
a[href$=".org"] {
font-style: italic;
}
/* <a> elements whose class attribute contains the word "logo" */
a[class~="logo"] {
padding: 2px;
}
/* 모든 span과 div 요소 선택 */
span,
div {
border: red 2px solid;
}
/* List items that are descendants of the "my-things" list */
ul.my-things li {
margin: 2em;
}
/* List items that are descendants of the "my-things" list */
ul.my-things li {
margin: 2em;
}
/* 서로 형제인 문단 중 이미지 뒤쪽인 경우에만 선택 */
img ~ p {
color: red;
}
/* Paragraphs that come immediately after any image */
img + p {
font-weight: bold;
}
출처
https://developer.mozilla.org/ko/docs/Web/CSS/CSS_selectors