CSS Graphics Geometry
Guide
Reference
GitHub
Guide
Reference
GitHub
  • Part 0. Math foundations

    • 좌표계와 CSS pixel
    • 점, 벡터, 거리와 기본 용어
    • 각도, 라디안, atan2
  • Part 1. Transform linear algebra

    • translate, scale, rotate
    • CSS matrix(a,b,c,d,e,f)
    • 변환 순서와 transform-origin
    • local, world, screen 좌표계
    • inverse matrix와 포인터 입력
    • 좌표와 transform 디버깅
  • Part 2. Infinite canvas math and architecture

    • viewport와 camera 모델
    • cursor anchored zoom
    • ruler와 tick 계산
    • 주기 함수와 grid step
    • content, overlay, controls layer
    • scene graph와 nested transform
  • Part 3. Editor tool math

    • Pointer Events와 드래그
    • DOMRect와 getBoundingClientRect
    • hit testing과 bounding box
    • selection rectangle과 marquee
    • selection bounds와 handles
    • resize와 rotation handle
    • snapping과 smart guides
    • group, frame, clipping
  • Part 4. CSS graphics properties as math

    • CSS box로 도형 만들기
    • clip-path, radius, shadow
    • 선형보간과 linear-gradient
    • 거리 함수와 radial/conic-gradient
    • stacking context와 합성
    • layout, paint, composite
  • Part 5. Editor state and persistence

    • 레이어 모델과 z-index
    • 이동, 복제, 삭제, 잠금
    • undo/redo command model
    • JSON export/import
  • Part 6. SVG overlay and vector editing

    • SVG viewBox와 좌표계
    • getScreenCTM과 inverse
    • SVG pointer-events와 stroke hit testing
    • cubic bezier path editing
    • mask, clipPath, marker
  • Part 7. Figma to CSS translation

    • Figma node와 CSS DOM 모델
    • Frame constraints와 Auto Layout
    • Fills, strokes, effects를 CSS로
    • Vector와 text 변환
    • gradient 밖의 CSS 수학
    • Figma gradient를 CSS gradient로 변환하기
    • 수학이 필요한 Figma to CSS 속성들
    • Figma VectorNetwork 정리
  • Appendix A. Canvas renderer transition

    • Canvas로 넘어가는 기준
  • Appendix B. Motion and timing

    • 모션 수학과 timing 함수
    • Keyframe timeline 엔진
    • Motion path 수학
    • Bezier curve 길이 구하기

stacking context와 합성

이번에는 누가 위에 그려지는가를 봅니다.

디자인 에디터에서 레이어 순서는 생명입니다. 사각형 A가 B 위에 있어야 하는데 브라우저가 반대로 그리면, 사용자는 바로 알아차립니다. “어? 왜 뒤로 갔지?” 이 한마디가 나오면 레이어 모델을 다시 봐야 합니다.

CSS에서는 이 순서를 z-index만으로 다 설명할 수 없습니다. 중간에 stacking context라는 지역 규칙이 끼어듭니다.

z-index는 전역 순위표가 아니다

처음에는 이렇게 생각하기 쉽습니다.

z-index가 크면 위에 그려진다.

대체로 맞지만, 항상 맞지는 않습니다. 어떤 요소가 새로운 stacking context를 만들면 그 안의 자식들은 그 지역 안에서만 순서를 겨룹니다. 동네 대회 1등이 전국 1등은 아닌 것과 비슷합니다.

새 stacking context를 만들 수 있는 대표적인 속성은 이런 것들입니다.

  • position과 z-index
  • opacity가 1보다 작은 경우
  • transform
  • filter
  • isolation

그래픽 에디터는 transform을 많이 씁니다. 그러니 stacking context를 자주 만들게 됩니다. 편집기는 이 점을 알고 있어야 합니다.

stacking context local layer order diagramcontext Az: 999context Bz: 1root order decides A vs B first. child z-index only competes inside its own context.
stacking context는 레이어 순서를 지역 단위로 봉인합니다. 자식 z-index가 커도 부모 context 밖으로 혼자 튀어나갈 수 없습니다.

합성은 레이어를 섞는 단계다

브라우저 렌더링은 대략 layout, paint, composite 단계로 이어집니다. stacking context는 어떤 단위로 paint하고 composite할지를 바꿉니다.

렌더링 순서는 tree order + stacking context + z-index의 정렬 문제다.
opacity < 1, transform, filter 등은 새 합성 단위를 만들 수 있다.
hit testing은 보통 위에서 아래 순서로 후보를 검사한다.

mix-blend-mode, opacity, filter 같은 속성은 단순히 색만 바꾸는 것이 아니라 합성 방식에도 영향을 줍니다. 그래서 편집기에서 blend mode를 지원하려면 CSS 렌더링 규칙과 모델의 레이어 순서를 같이 맞춰야 합니다.

편집기 모델과 DOM 순서를 맞추기

레이어 패널에서 위에 있는 오브젝트가 화면에서도 위에 보여야 합니다. 가장 단순한 방법은 DOM 순서를 모델 순서와 맞추는 것입니다.

model.layers[0] = back
model.layers[n] = front
render DOM in same order

필요하다면 z-index를 쓰되, stacking context가 생기는 지점을 의도적으로 관리해야 합니다. 특히 selection overlay는 content layer보다 항상 위에 있어야 하므로 별도 overlay layer로 분리하는 편이 안정적입니다.

데모에서 볼 것

데모에서는 z-index, opacity, transform이 레이어 순서와 합성에 어떤 영향을 주는지 봅니다.

오늘의 교훈은 이겁니다. CSS 레이어는 단순한 숫자 싸움이 아닙니다. 지역 규칙이 있습니다. 편집기를 만들 때는 브라우저의 stacking 규칙을 외면하지 말고, 모델의 레이어 순서와 의도적으로 맞춰야 합니다.

Edit this page
최근 수정: 26. 5. 14. PM 5:45
Contributors: easylogic
Prev
거리 함수와 radial/conic-gradient
Next
layout, paint, composite