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

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

 

결과보기



분류 제목
font CSS - font-feature-settings 속성 - OpenType 글꼴의 고급 인쇄 기능 제어 (=…
css CSS - place-content 속성(C) - (flex/grid) 레이아웃에서 (수직정렬/수평정렬) 일…
scroll CSS - scroll-padding-inline-end 속성 -
grid CSS - grid-auto-flow 속성(C) - 그리드 컨테이너 채우는 방식 지정 (= grid-auto…
grid CSS - grid-row-gap 속성 - (※ row-gap으로 이름 바뀜.) 그리드 행 간격 지정 (= …
position CSS - overflow-x 속성 - 수평방향으로 넘치는 내용 처리 방법 지정 (= overflow-x속성…
scroll CSS - scroll-margin 속성 - 스크롤마진 일괄 지정 (= scroll-margin속성 = 스크…
css CSS - isolation 속성 - 요소가 새 스택(stack: 쌓음) 콘텐츠를 생성해야 하는지 여부 지정…
scroll CSS - scroll-behavior 속성 ★ - 스크롤박스 내 동일 페이지 링크 이동 시 부드럽게 이동할…
grid CSS - grid-auto-columns 속성(C) - 그리드 열 너비 일괄 지정 (= grid-auto-…
background CSS - background-position-x 속성 - 배경이미지 x축위치(=수평위치) 설정 (= bac…
grid CSS - grid-row 속성(I) - 그리드 아이템 행 '시작위치와 끝위치 / 크기확장' 지정 (= gr…
grid CSS - grid-row-start 속성(I) - 그리드 아이템 행 시작 위치 및 확장 지정 (= grid…
box CSS - box-decoration-break 속성 - 요소 상자 깨지는 방식 지정 (= box-decor…
image CSS - image-rendering 속성 - 크기 조정 가능 이미지의 렌더링 방식 지정 (= image-…
grid CSS - grid-auto-rows 속성(C) - 그리드 행 높이 일괄 지정 (= grid-auto-row…
scroll CSS - scrollbar-color 속성 - 스크롤바 색상 지정 (= scrollbar-color속성 =…
background CSS - background-blend-mode 속성 - 해당요소 각 (배경색/배경미미지)층의 혼합방식 지…
css CSS - accent-color 속성 - 사용자 제어 선택요소의 색상/색깔 지정 (= accent-colo…
grid CSS - grid-template 속성 - 그리드 행열 및 영역 개별 지정 (= grid-template속…
9/27
목록
찾아주셔서 감사합니다. Since 2012