CSS

[counter] CSS - counter() 함수 / counters() 함수 - 카운터 값을 요소에 추가 (= counter함수 / counters함수 = 카운터함수/카운터스함수/카운터즈함수)

목차
  1. counter() 예제 - 2번째 매개변수 사용 X 경우
  2. counter() 정의
  3. counter() 구문
  4. counter() 예제 - 2번째 매개변수 사용 O 경우
  5. counter() 예제 - counters() 함수 사용 경우

 

counter() 예제 - 2번째 매개변수 사용 X 경우

[예제1] - body 요소에서 index 카운터변수 초기화 한 경우

 

<style>

body {counter-reset: index;}

h2::before {

  counter-increment: index;

  content: "목차 " counter(index) ": ";

}

</style>


<h1>그누보드 앞단 언어</h1>

<h2>HTML 매뉴얼</h2>

<h2>CSS 매뉴얼</h2>

<h2>JavaScript 매뉴얼</h2>


<h1>그누보드 뒷단 언어</h1>

<h2>PHP 매뉴얼</h2>

<h2>SQL 매뉴얼</h2>

 

결과보기


[예제2] - h1요소에서 index 카운터변수 초기화 한 경우

 

<style>

h1 {counter-reset: index;}

h2::before {

  counter-increment: index;

  content: "목차 " counter(index) ": ";

}

</style>


<h1>그누보드 앞단 언어</h1>

<h2>HTML 매뉴얼</h2>

<h2>CSS 매뉴얼</h2>

<h2>JavaScript 매뉴얼</h2>


<h1>그누보드 뒷단 언어</h1>

<h2>PHP 매뉴얼</h2>

<h2>SQL 매뉴얼</h2>

 

결과보기

 

 

counter() 정의

 

지정 카운터 변수의 현재값을 string (문자열) 타입으로 반환.

 


 

1.

CSS버전: CSS3

 

2.

모든 브라우저 지원.

 

 

counter() 구문

 

  • counter(counterName, counterStyle)
  • counters(counterName, counterStyle)

 

PS. 중첩구조 (=안긴형태)일 땐, counters() 함수 사용.


[속성값]

 

counterName

필수. 카운터 변수 이름

 

counterStyle

선택. 카운터 스타일

 


[반환값]

 

지정 카운터 변수의 현재값 반환. (string 타입)

 

 

counter() 예제 - 2번째 매개변수 사용 O 경우

[예제1] - body 요소에서 index 카운터변수 초기화 한 경우

 

<style>

body {counter-reset: index;}

h2::before {

  counter-increment: index;

  content: "목차 " counter(index, upper-roman) ": ";

}

</style>


<h1>그누보드 앞단 언어</h1>

<h2>HTML 매뉴얼</h2>

<h2>CSS 매뉴얼</h2>

<h2>JavaScript 매뉴얼</h2>


<h1>그누보드 뒷단 언어</h1>

<h2>PHP 매뉴얼</h2>

<h2>SQL 매뉴얼</h2>

 

결과보기


[예제2] - h1요소에서 index 카운터변수 초기화 한 경우

 

<style>

h1 {counter-reset: index;}

h2::before {

  counter-increment: index;

  content: "목차 " counter(index, upper-roman) ": ";

}

</style>


<h1>그누보드 앞단 언어</h1>

<h2>HTML 매뉴얼</h2>

<h2>CSS 매뉴얼</h2>

<h2>JavaScript 매뉴얼</h2>


<h1>그누보드 뒷단 언어</h1>

<h2>PHP 매뉴얼</h2>

<h2>SQL 매뉴얼</h2><style>

 

결과보기

 

counter() 예제 - counters() 함수 사용 경우


<style>

ol {

  counter-reset: index;

  list-style-type: none;

}


li::before {

  counter-increment: index;

  content: counters(index,".") " - ";

}

</style>


첫 번째 OL 요소

<ol>

  <li>홈짱닷컴</li>

  <li>홈짱닷컴   

  <ol>

    <li>홈짱닷컴</li>

    <li>홈짱닷컴</li>

    <li>홈짱닷컴

    <ol>

      <li>홈짱닷컴</li>

      <li>홈짱닷컴</li>

      <li>홈짱닷컴</li>

    </ol>

    </li>

    <li>홈짱닷컴</li>

  </ol>

  </li>

  <li>홈짱닷컴</li>

  <li>홈짱닷컴</li>

</ol>


두 번째 OL 요소

<ol>

  <li>홈짱닷컴</li>

  <li>홈짱닷컴</li>

  <li>홈짱닷컴</li>

</ol>


결과보기

PS. 중첩구조에서 counter() 함수 사용 시, 카운터 작동 X (예제)

 


분류 제목
animation CSS - animation-name 속성 - 키프레임명 (= 키프레임이름 = 애니이름 = 애니명 = 애니메…
animation CSS - animation-fill-mode 속성 - 애니미작동스타일 (= 움직임 작동안할때 스타일 = 애…
column CSS - column-width 속성 - 컬럼 너비 지정 (= column-width속성 = 컬럼위드스속성…
css CSS - 반응형 마름모 갤러리 (Responsible Rhomb gallery on grids + clip…
background CSS - background-origin 속성 - 배경이미지 좌표시작점 (= 백그라운드오리진 속성)
css CSS - unset 속성값 - 상속값 존재 유무에 따라, inherit・initial 속성값 사용. (= …
selector CSS - [attribute^=value] 속성선택자 ★ - 지정 속성값 문자열로 시작하는 요소. (=시…
border CSS - border-bottom-width 속성 - 테두리하단너비 (= 테두리하단두께 = border-b…
responsive CSS - RES Grid-View - (그리드뷰 = 화면너비분할 = 화면분할 = 수동그리드)
selector CSS - [attribute~=value] 속성선택자 - 특정 속성값단어 (단독 또는 단어앞뒤공백)인 요소…
selector CSS - [attribute$=value] 속성선택자 - 지정 속성값 문자열로 끝나는 요소 (IE7)
selector CSS - :placeholder-shown 가상선택자 - 플레이스홀더 텍스트 표시 중인 요소 선택 (= :…
border CSS - border-right-style 속성 - 테두리우측모양 (= border-right-style속…
gradient CSS - linear-gradient() 함수 ★ - 선형 그레이디언트 배경이미지 (= 선형 그라디언트 …
border CSS - border-top-left-radius 속성 - 테두리상단왼쪽둥글기 지정 (= 보더탑레프트레이디…
22/35
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인