CSS 튜토리얼

CSS 홈 CSS 소개 CSS 구문 CSS 선택기 CSS 방법 CSS 주석 CSS 색상 CSS 배경 CSS 테두리 CSS 여백 CSS 패딩 CSS 높이/너비 CSS 상자 모델 CSS 개요 CSS 텍스트 CSS 글꼴 CSS 아이콘 CSS 링크 CSS 목록 CSS 테이블 CSS 디스플레이 CSS 최대 너비 CSS 위치 CSS Z-색인 CSS 오버플로 CSS 플로트 CSS 인라인 블록 CSS 정렬 CSS 결합기 CSS 의사 클래스 CSS 의사 요소 CSS 불투명도 CSS 탐색 모음 CSS 드롭다운 CSS 이미지 갤러리 CSS 이미지 스프라이트 CSS 속성 선택기 CSS 양식 CSS 카운터 CSS 웹사이트 레이아웃 CSS 단위 CSS 특수성 CSS !중요 CSS 수학 함수

CSS 고급

CSS 둥근 모서리 CSS 테두리 이미지 CSS 배경 CSS 색상 CSS 색상 키워드 CSS 그라디언트 CSS 그림자 CSS 텍스트 효과 CSS 웹 글꼴 CSS 2D 변환 CSS 3D 변환 CSS 전환 CSS 애니메이션 CSS 도구 설명 CSS 스타일 이미지 CSS 이미지 반사 CSS 객체 맞춤 CSS 객체 위치 CSS 마스킹 CSS 버튼 CSS 페이지 매김 CSS 다중 열 CSS 사용자 인터페이스 CSS 변수 CSS 상자 크기 조정 CSS 미디어 쿼리 CSS MQ 예 CSS 플렉스박스

CSS 반응형

RWD 소개 RWD 뷰포트 RWD 그리드 보기 RWD 미디어 쿼리 RWD 이미지 RWD 비디오 RWD 프레임워크 RWD 템플릿

CSS 그리드

그리드 소개 그리드 컨테이너 그리드 항목

CSS SASS

SASS 튜토리얼

CSS 예제

CSS 템플릿 CSS 예제 CSS 퀴즈 CSS 연습 CSS 인증서

CSS 참조

CSS 참조 CSS 선택기 CSS 함수 CSS 참조 청각 CSS 웹 안전 글꼴 CSS 애니메이션 가능 CSS 단위 CSS PX-EM 변환기 CSS 색상 CSS 색상 값 CSS 기본값 CSS 브라우저 지원

CSS 의사 요소


의사 요소 란 무엇입니까?

CSS 의사 요소는 요소의 지정된 부분에 스타일을 지정하는 데 사용됩니다.

예를 들어 다음과 같은 용도로 사용할 수 있습니다.

  • 요소의 첫 글자 또는 줄 스타일 지정
  • 요소의 내용 앞이나 뒤에 내용 삽입

통사론

의사 요소의 구문:

selector::pseudo-element {
  property: value;
}

::첫 번째 줄 의사 요소

::first-line의사 요소는 텍스트의 첫 번째 줄에 특별한 스타일을 추가하는 데 사용됩니다 .

다음 예제에서는 모든 <p> 요소에 있는 텍스트의 첫 번째 줄에 서식을 지정합니다.

예시 

p::first-line {
  color: #ff0000;
  font-variant: small-caps;
}

참고: 의사 ::first-line요소는 블록 수준 요소에만 적용할 수 있습니다.

::first-line 의사 요소 에는 다음 속성이 적용됩니다 .

  • 글꼴 속성
  • 색상 속성
  • 배경 속성
  • 단어 간격
  • 문자 간격
  • 텍스트 장식
  • 수직 정렬
  • 텍스트 변환
  • 줄 높이
  • 분명한

이중 콜론 표기법에 주목하세요. 이중 콜론 ::first-line 이 CSS3 :first-line

의 의사 요소에 대한 단일 콜론 표기법을 대체했습니다. 이것은 의사 클래스의사 요소 를 구별하기 위한 W3C의 시도였습니다 .

단일 콜론 구문은 CSS2 및 CSS1에서 의사 클래스와 의사 요소 모두에 사용되었습니다.

이전 버전과의 호환성을 위해 단일 콜론 구문은 CSS2 및 CSS1 의사 요소에 대해 허용됩니다.



::첫 글자 의사 요소

의사 요소는 텍스트의 첫 ::first-letter글자에 특별한 스타일을 추가하는 데 사용됩니다.

다음 예제에서는 모든 <p> 요소에 있는 텍스트의 첫 글자에 서식을 지정합니다. 

예시

p::first-letter {
  color: #ff0000;
  font-size: xx-large;
}

참고: 의사 ::first-letter요소는 블록 수준 요소에만 적용할 수 있습니다.

다음 속성이 ::first-letter 의사 요소에 적용됩니다. 

  • 글꼴 속성
  • 색상 속성 
  • 배경 속성
  • 여백 속성
  • 패딩 속성
  • 테두리 속성
  • 텍스트 장식
  • vertical-align("float"이 "none"인 경우에만)
  • 텍스트 변환
  • 줄 높이
  • 뜨다
  • 분명한

의사 요소 및 HTML 클래스

의사 요소는 HTML 클래스와 결합할 수 있습니다. 

예시

p.intro::first-letter {
  color: #ff0000;
  font-size: 200%;
}

위의 예는 class="intro"인 단락의 첫 글자를 빨간색으로 더 큰 크기로 표시합니다.


다중 의사 요소

여러 유사 요소를 결합할 수도 있습니다.

다음 예에서 단락의 첫 글자는 xx-large 글꼴 크기에서 빨간색입니다. 첫 번째 줄의 나머지 부분은 파란색이며 작은 대문자로 표시됩니다. 단락의 나머지 부분은 기본 글꼴 크기와 색상이 됩니다.

예시

p::first-letter {
  color: #ff0000;
  font-size: xx-large;
}

p::first-line {
  color: #0000ff;
  font-variant: small-caps;
}

CSS - ::before Pseudo-element

의사 요소를 사용하여 요소 의 ::before콘텐츠 앞에 일부 콘텐츠를 삽입할 수 있습니다.

다음 예에서는 각 <h1> 요소의 내용 앞에 이미지를 삽입합니다.

예시

h1::before {
  content: url(smiley.gif);
}

CSS - ::after 의사 요소

의사 요소는 요소 의 ::after내용 뒤에 일부 내용을 삽입하는 데 사용할 수 있습니다.

다음 예에서는 각 <h1> 요소의 내용 뒤에 이미지를 삽입합니다.

예시

h1::after {
  content: url(smiley.gif);
}

CSS - ::marker 의사 요소

::marker의사 요소는 목록 항목의 마커를 선택합니다 .

다음 예제에서는 목록 항목의 마커 스타일을 지정합니다.

예시

::marker {
  color: red;
  font-size: 23px;
}

CSS - ::selection 의사 요소

::selection의사 요소는 사용자가 선택한 요소의 부분과 일치합니다 .

, , 에 적용할 수 있는 CSS 속성은 다음과 ::selection같습니다 .colorbackgroundcursoroutline

다음 예에서는 선택한 텍스트를 노란색 배경에 빨간색으로 만듭니다.

예시

::selection {
  color: red;
  background: yellow;
}

연습으로 자신을 테스트하십시오

연습:

단락의 첫 번째 줄의 background-color를 빨간색으로 설정합니다.

<style>
 {
  background-color: red;
}
</style>

<body>

<p class="intro">
In my younger and more vulnerable years
my father gave me some advice that I've
been turning over in my mind ever since.
'Whenever you feel like criticizing anyone,' he told me,
'just remember that all the people in this world
haven't had the advantages that you've had.'
</p>

</body>


모든 CSS 유사 요소

Selector Example Example description
::after p::after Insert something after the content of each <p> element
::before p::before Insert something before the content of each <p> element
::first-letter p::first-letter Selects the first letter of each <p> element
::first-line p::first-line Selects the first line of each <p> element
::marker ::marker Selects the markers of list items
::selection p::selection Selects the portion of an element that is selected by a user

모든 CSS 의사 클래스

Selector Example Example description
:active a:active Selects the active link
:checked input:checked Selects every checked <input> element
:disabled input:disabled Selects every disabled <input> element
:empty p:empty Selects every <p> element that has no children
:enabled input:enabled Selects every enabled <input> element
:first-child p:first-child Selects every <p> elements that is the first child of its parent
:first-of-type p:first-of-type Selects every <p> element that is the first <p> element of its parent
:focus input:focus Selects the <input> element that has focus
:hover a:hover Selects links on mouse over
:in-range input:in-range Selects <input> elements with a value within a specified range
:invalid input:invalid Selects all <input> elements with an invalid value
:lang(language) p:lang(it) Selects every <p> element with a lang attribute value starting with "it"
:last-child p:last-child Selects every <p> elements that is the last child of its parent
:last-of-type p:last-of-type Selects every <p> element that is the last <p> element of its parent
:link a:link Selects all unvisited links
:not(selector) :not(p) Selects every element that is not a <p> element
:nth-child(n) p:nth-child(2) Selects every <p> element that is the second child of its parent
:nth-last-child(n) p:nth-last-child(2) Selects every <p> element that is the second child of its parent, counting from the last child
:nth-last-of-type(n) p:nth-last-of-type(2) Selects every <p> element that is the second <p> element of its parent, counting from the last child
:nth-of-type(n) p:nth-of-type(2) Selects every <p> element that is the second <p> element of its parent
:only-of-type p:only-of-type Selects every <p> element that is the only <p> element of its parent
:only-child p:only-child Selects every <p> element that is the only child of its parent
:optional input:optional Selects <input> elements with no "required" attribute
:out-of-range input:out-of-range Selects <input> elements with a value outside a specified range
:read-only input:read-only Selects <input> elements with a "readonly" attribute specified
:read-write input:read-write Selects <input> elements with no "readonly" attribute
:required input:required Selects <input> elements with a "required" attribute specified
:root root Selects the document's root element
:target #news:target Selects the current active #news element (clicked on a URL containing that anchor name)
:valid input:valid Selects all <input> elements with a valid value
:visited a:visited Selects all visited links