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

[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>

 

결과보기



분류 제목
gradient CSS - repeating-radial-gradient () 함수 - 방사형 그레이디언트 반복 (= 그라디…
selector CSS - :read-write 가상선택자 - 읽고쓰기가능요소 (= readonly속성없는요소, IE13)
border CSS - border-image-outset 속성 - 테두리 경계 넘는 이미지 양. (= 보더이미지아웃셋속…
selector CSS - :optional 가상선택자 - 선택입력요소 (= required 속성없는 요소, IE10)
responsive CSS - RES Intro - (반응형 웹디자인 소개)
css CSS - 구글 로그인 포커스 애니 효과 (Google Logn Foucs Animation Effect) …
pagination CSS - 페이징 - 둥근테두리 효과 (Rounded bordered pagination)
image CSS - Thumbnail Images - (썸네일 이미지 스타일)
pagination CSS - 페이징 - 트랜지션 효과 (Hoverable Transition Effect)
selector CSS - .class1 .class2 클래스선택자 ★★ - class1자손 중 class2 갖는 모든 요소
gradient CSS - repeating-linear-gradient () 함수 - 반복 선형 그레이디언트 ※ 패턴 배경
image CSS - object-fit 속성 - 컨테이너에 맞게 '이미지/비디오' 크기 조정 방법 지정 (= obje…
border CSS - border-image-source 속성 - 테두리 이미지 주소 (= border-image-so…
border CSS - border-right 속성 - 테두리우측일괄 (= 테두리오른쪽일괄 = border-right속성…
pagination CSS - 페이징 - 가운데 정렬 (Centered Pagination)
animation CSS - animation-timing-function 속성 - 애니재생중속도변화 (= 움직임 중 속도변경…
border CSS - border-left-style 속성 - 테두리좌측모양 (= 테두리왼쪽모양 = border-lef…
border CSS - border-image-width 속성 - 테두리 이미지 너비 (= border-image-wid…
border CSS - border-right-color 속성 - 테두리우측색상 (= 테두리오른쪽색상 = 테두리우측색깔…
border CSS - border-top-style 속성 - 테두리상단모양 (= 테두리상단스타일 = border-top…
14/27
목록
찾아주셔서 감사합니다. Since 2012