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

[counter] CSS - counter-increment 속성 - 카운터 값 증가 (= counter-increment속성 = 카운터인크리먼트속성)

목차

  1. counter-increment 예제 - 1씩 증가
  2. counter-increment 정의
  3. counter-increment 구문
  4. counter-increment 예제 - 1씩 감소
  5. counter-increment 예제 - 중첩구조
  6. counter-increment 예제 - 로마자로 1씩 증가

 

counter-increment 예제 - 1씩 증가

 

<style>

body {

  counter-reset: index;

}


h2::before {

  counter-increment: index;

  content: "◎ " counter(index) ". ";

}

</style>


<h2>HTML - 구조</h2>

<h2>CSS - 디자인</h2>

<h2>JavaScript - 기능</h2>

 

결과보기

 

counter-increment 정의

 

지정된 카운터변수에 대해서 증감 정도 지정.

 


 

1. 함께 사용하는 속성

  • counter-reset 속성 - 카운터변수 생성 및 초기값 재설정.
  • content 속성 - 해당 요소 앞에 카운터 삽입

 

2.

  • 기본값: none
  • 상속여부: X
  • 애니가능: X
  • CSS버전: CSS2
  • JS버전: object.style.counterIncrement = "index";

 

3.

IE8 이상 주요 최신 브라우저 모두 지원.

 

 

counter-increment 구문

 

selector {counter-increment: none|name number|initial|inherit;}

 


[속성값]

 

none

증감 X (기본값)

 

name number

카운터변수 name에 대해서 number 만큼 증감 지정. (number 미지정 시 기본값: 1)

  • namenumber는 띄워씀.
  • number 앞 플러스(+)/마이너스(-)부호는 숫자와 딱 붙여씀.
  • number 앞 플러스(+) 기호는 생략 가능.
  • name이 counter-reset 속성에 의해 '생성/초기화재설정' 안 되어 있는 경우 name 초기값은 0임.

 

initial

이 속성의 기본값으로 지정. 

 

inherit

부모요소의 속성값 상속.

 

 

counter-increment 예제 - 1씩 감소

  • name과 number는 한 칸 띄워야 하며, 부호는 number에 붙임.
  • 플러스(+) 부호는 생략 가능.

 

<style>

body {

  counter-reset: index;

}


h2::before {

  counter-increment: index -1;

  content: "◎ " counter(index) ". ";

}

</style>


<h2>HTML - 구조</h2>

<h2>CSS - 디자인</h2>

<h2>JavaScript - 기능</h2>

 

결과보기

 

counter-increment 예제 - 중첩구조

 

<style>

body {

  counter-reset: index;

}


h1 {

  counter-reset: sub_index;

}


h1::before {

  counter-increment: index;

  content: "◎ " counter(index) ": ";

}


h2::before {

  counter-increment: sub_index;

  content: counter(index) "." counter(sub_index) " ";

}

</style>


<h1>브라우저측 언어</h1>

<h2>HTML</h2>

<h2>CSS</h2>

<h2>JavaScript</h2>

<hr>


<h1>서버측 언어</h1>

<h2>PHP</h2>

<h2>SQL</h2>


결과보기

 

counter-increment 예제 - 로마자로 1씩 증가

※ content 속성의 값에 counter()/counters() 함수 2번째 매개변수에 upper-roman 지정.

 

<style>

body {

  counter-reset: index;

}


h2::before {

  counter-increment: index;

  content: "◎ " counter(index, upper-roman) ". ";

}

</style>


<h2>HTML - 구조</h2>

<h2>CSS - 디자인</h2>

<h2>JavaScript - 기능</h2>

 

결과보기



분류 제목
outline CSS - outline-color 속성 - 외곽선두께 (= 아웃라인컬러속성 = outline-color속성…
box CSS - width 속성 ★ - 너비 (= 가로길이 = width속성 = 위드스속성, 상속X)
box CSS - height 속성 ★ - 높이 (= 세로길이 = height속성 = 하이트속성) (※ vh, vw…
box CSS - min-width 속성 - 최소너비 (=최소가로길이 = min-width속성 = 민위드스속성)
box CSS - min-height 속성 - 최소높이 (= 최소세로길이 = min-height속성 = 민하이트속성…
box CSS - max-width 속성 - 최대너비 (= 최대가로길이 = max-width속성 = 맥스위드스속성)
box CSS - max-height 속성 - 최대높이 (= 최대세로길이 = max-height속성 = 맥스하이트속…
font CSS - font 속성 ★ - 글자스타일종합 (= font속성 = 글씨체 = 서체 = 글꼴 = 폰트속성, …
font CSS - font-size 속성 ★ - 글자크기 (= 글씨체크기= 글씨크기 = 서체크기= 글씨크기 = …
font CSS - font-family 속성 ★ - 글자종류 (= font-family속성 = 폰트패밀리속성 = 글…
font CSS - font-weight 속성 ★ - 글자굵기 (= font-weight속성 = 폰트굵기 = 글씨체굵…
font CSS - font-style 속성 - 글자기울기 (= 이텔릭체 여부 = 이탤릭 글씨체 = 글자 기울려쓰기 … 1
font CSS - font-variant 속성 - 작은 대문자 (= font-variant속성 = 폰트베리언트 = …
text CSS - color 속성 ★ - 글자색깔 (=글자색상=글자색깔=글자컬러 = 텍스트색깔 = 컬러속성 = co…
text CSS - direction 속성 - 텍스트방향 (= 텍스트진행방향 = direction속성 = 디렉션속성)…
text CSS - letter-spacing 속성 ★ - 글자 간격 사이사이 띄우기 ( 텍스트사이띄우기 = 문자 간…
text CSS - line-height 속성 ★ - 텍스트라인높이 (= line-height속성 = 텍스트줄높이 =…
text CSS - text-align 속성 ★ - 텍스트정렬 (= text-align속성 = 텍스트얼라인속성)
text CSS - text-decoration 속성 ★ - 텍스트라인 꾸미기 (= 밑줄/밑선, 가운데줄/취소선, 윗…
text CSS - text-indent 속성 ★★ - 단락 첫줄 텍스트 들여쓰기 (= text-indent속성 = …
4/25
목록
찾아주셔서 감사합니다. Since 2012