home강의 홈으로
Section 4. CSS 더 깊이 알아보기
Lesson 2. 선택자 심화

/* 속성 값을 기준으로 선택 */ a[href="https://www.yalco.kr"] { color: #ff4e00; font-weight: bold; } /* 특정 속성이 있는 요소 선택 */ input[disabled]+label { color: lightgray; text-decoration: line-through; } /* 속성값이 특정 텍스트를 포함하는 요소 */ span[class*="item"] { text-decoration: underline; } /* 속성값이 특정 텍스트로 시작하는 요소 */ span[class^="fruit"] { color: tomato; } span[class^="vege"] { color: olivedrab; } /* 속성값이 특정 텍스트로 끝나는 요소 */ span[class$="-1"] { font-weight: bold; }

👉 특성 선택자 MDN 문서







/* 마우스오버 */ a:hover { background-color: yellow; } /* 클릭중 */ a:active { background-color: aqua; } /* 체크된 것 */ input[type=radio]:checked+label { color: tomato; font-weight: bold; } /* 활성화된 것 */ input[type=radio]:enabled+label { text-decoration: underline; } /* 비활성화된 것 */ input[type=radio]:disabled+label { color: lightgray; text-decoration: line-through; }




/* 인풋 등이 클릭되어 포커스된(입력을 받는) 상태 */ input[type="text"]:focus { /* border 밖의 선 (박스 요소가 아님) */ outline: 2px solid dodgerblue; } /* 필수 입력요소 */ input:required { border-color: orangered; } /* 값이 유효한 입력요소 */ input[type="email"]:valid { border-color: green; } /* 값이 무효한 입력요소 */ input[type="email"]:not(:valid) { border-color: purple; } [class*="focus"]:focus { outline: 2px solid deeppink; } .tab-focus:focus, .no-focus:focus { outline: none; } /* 탭으로 포커스된 요소에 적용 */ /* 브라우저 지원 확인 */ [class*="tab-focus"]:focus-visible { outline: 2px solid dodgerblue; }

focus 관련 기능은 브라우저에 따라 제대로 지원되지 않기도(사파리 등) 합니다.

타이핑 인풋 요소(예: 텍스트 인풋)들은 focus-visible을 사용해도 클릭과 탭 모두에 반응(아웃라인 표시 등)합니다.





/* 부모 요소 내 첫 번째 ~요소 */ b:first-of-type { text-decoration: overline; } /* 부모 요소 내 마지막 ~요소 */ i:last-of-type { text-decoration: line-through; } /* 부모 요소 내 N번째 ~요소 */ b:nth-of-type(2) { text-decoration: underline; } /* 부모 요소 내 유일한 ~요소 */ div :only-of-type { text-decoration: overline line-through underline; } /* 부모 요소 내 종류 무관 유일한 요소 (독자) */ div :only-child { text-decoration: wavy underline tomato; }

👉 가상 클래스 MDN 문서







li.later::after { content: '다음 강좌'; margin-left: 0.6em; padding: 0.16em 0.36em; font-size: 0.72em; font-weight: bold; color: white; background-color: darkmagenta; border-radius: 0.2em; } /* 바로 앞에 가상의 요소 추가 */ li::before { content: ''; display: inline-block; margin: 0 0.4em; width: 0.8em; height: 0.8em; background-image: url(./check.png); background-size: contain; } /* 선택 영역 가상 요소 */ .orange::selection { background-color: orange; } .dark::selection { color: lightgreen; background-color: #222; } /* 플레이스홀더 가상 요소 */ input:required::placeholder { color: darkred; background-color: yellow; }

👉 가상 요소 MDN 문서

🤔얄코에게 질문하기질문은 반.드.시 이리로 보내주세요! ( 강의사이트 질문기능 ✖ )

강의에서 이해가 안 되거나 실습상 문제가 있는 부분,
설명이 잘못되었거나 미흡한 부분을 메일로 알려주세요!

답변드린 뒤 필요할 경우 본 페이지에
관련 내용을 추가/수정하도록 하겠습니다.

이메일 주소
yalco@yalco.kr
메일 제목 (반드시 아래 제목을 붙여넣어주세요!)
[질문] 제대로 파는 HTML & CSS (유료 파트) 4-2

🛑질문 전 필독!!

  • 구글링을 먼저 해 주세요. 들어오는 질문의 절반 이상은 구글에 검색해 보면 1분 이내로 답을 찾을 수 있는 내용들입니다.
  • 오류 메시지가 있을 경우 이를 구글에 복붙해서 검색해보면 대부분 짧은 시간 내 해결방법을 찾을 수 있습니다.
  • 강의 페이지에 추가사항 등 놓친 부분이 없는지 확인해주세요. 자주 들어오는 질문은 페이지에 추가사항으로 업데이트됩니다.
  • "유료파트의 강의페이지는 어디 있나요?" - 각 영상의 시작부분 검은 화면마다 해당 챕터의 강의페이지 링크가 있습니다.
  • 질문을 보내주실 때는 문제가 어떻게 발생했고 어떤 상황인지 등을 구체적으로 적어주세요. 스크린샷을 첨부해주시면 더욱 좋습니다.
🌏 Why not change the world?