• 회원가입
  • 로그인
  • 구글아이디로 로그인

[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 (예제)

 


분류 제목
intro CSS - 브라우저 접두어 (= vendor prefix = 벤더 프리픽스)
border CSS - border-radius 속성 ★ - 테두리둥글기 지정 (= border-radius속성 = 보더…
border CSS - border-top-left-radius 속성 - 테두리상단왼쪽둥글기 지정 (= 보더탑레프트레이디…
border CSS - border-top-right-radius 속성 - 테두리상단우측둥글기 지정 (= 보더탑라이트레이…
border CSS - border-bottom-right-radius 속성 - 테두리 하단 오른쪽 모서리 둥글게 (= …
border CSS - border-bottom-left-radius 속성 - 테두리하단왼쪽모서리둥글게 (= border…
border CSS - border-image 속성 - 테두리이미지 (= border-image속성 = 보더이미지속성, …
border CSS - border-image-source 속성 - 테두리 이미지 주소 (= border-image-so…
border CSS - border-image-slice 속성 - 테두리이미지자르기 (IE11)
border CSS - border-image-width 속성 - 테두리 이미지 너비 (= border-image-wid…
border CSS - border-image-outset 속성 - 테두리 경계 넘는 이미지 양. (= 보더이미지아웃셋속…
border CSS - border-image-repeat 속성 - 테두리 이미지 반복할지 늘릴지 선택 (= 보더이미지리…
background CSS - background-clip 속성 - 배경영역 (= background-clip속성 = 백그라운드…
background CSS - background-origin 속성 - 배경이미지 좌표시작점 (= 백그라운드오리진 속성)
background CSS - background-size 속성 ★ - 배경이미지 크기 (background-size속성 = 백…
color CSS - RGBA , HSL , HSLA , opacity - (색상코드)
gradient CSS - Gradient (그레이디언트 = 그라디언트) 종류 - (색번짐변화=색변화) : IE 10
shadow CSS - text-shadow 속성 - 글자 그림자/음영 효과 주기 (= text-shadow속성 = 텍스…
shadow CSS - box-shadow 속성 - 요소 그림자 효과 주기 (= box-shadow속성 = 박스섀도속성)…
text CSS - text-align-last 속성 - 단락마지막라인정렬 (= text-align-last속성 = …
7/25
목록
찾아주셔서 감사합니다. Since 2012