Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
親に向かってなんだそのz-indexは
Search
sadnessOjisan
September 18, 2018
Technology
9.4k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
親に向かってなんだそのz-indexは
z-indexなんぞやを覚えてしまった不良息子をどう更生させるか、その感動秘話。
→ stack context に閉じ込めたり、portalで追い出せばいいと思う。
sadnessOjisan
September 18, 2018
More Decks by sadnessOjisan
See All by sadnessOjisan
Cloudflare Workers で Rust 選ぶ理由 is 何?
sadnessojisan
1
290
AIエージェントが動かないときの原因とその対処
sadnessojisan
2
170
React のルーター事情
sadnessojisan
1
670
PHPこそ OpenTelemetry が嬉しい
sadnessojisan
2
510
TypeScript、上達の瞬間
sadnessojisan
54
19k
フロントエンド・オブザーバビリティを支える要素技術を学ぼう
sadnessojisan
2
1k
疎通2024
sadnessojisan
5
1.7k
BasicBasic認証
sadnessojisan
5
5k
ISUCON入門以前_ISUNARABE_LT#1
sadnessojisan
21
6.8k
Other Decks in Technology
See All in Technology
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
1
1.6k
SDDの運用にめげずに向き合った話
sansantech
PRO
1
140
自作バイナリを動かす「入口」8選
puhitaku
2
1.3k
ハードウェアコンペでもAI駆動開発が進んでいる話
iotengineer22
1
680
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
370
今さら理解するウェブフォントver.2026
takanorip
3
650
しろおびから始める!ログ活用の第一歩
shumei_ito
0
870
契約書画像からの情報抽出に特化した視覚接地モデルを育てる話
sansantech
PRO
1
160
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
1.1k
AI時代のPRレビューにどう向き合うか?
kairim0
1
160
Deep Data Security 機能解説
oracle4engineer
PRO
2
760
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
5
1.2k
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
520
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
580
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
A better future with KSS
kneath
240
18k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
30 Presentation Tips
portentint
PRO
1
420
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
560
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Building the Perfect Custom Keyboard
takai
2
900
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
Transcript
親に向かってなんだその z-indexは!! Yuta Ide(@oijsan) 1
Yuta Ide(@ojisan) 株式会社リクルートライフスタイル 新卒2年⽬ • React • Redux & redux-saga
• NextJS • GatsbyJS Airメイト (PC / iPad / Mobile ) 2
3
_⼈⼈⼈⼈⼈⼈⼈⼈⼈⼈⼈⼈⼈⼈⼈⼈_ > JSのイベントなのに, CSSのお話 <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^ ̄ 4
今⽇、話すこと • 要素の重なり順の扱い⽅ • z-indexにまつわる怪奇現象 5
プランナー「管理テーブル作ってほしいな」 6
つくったもの 7
つくったもの 枠内スクロール スクロール固定(position: sticky) モーダルの開閉 ツールチップ z-indexを⾼く設定(スク ロールの⼀番⼿前に来る) 8
つくったもの モーダルを閉じるボタン モーダルを閉じようとすると確認ダイアログ 9
案件前のお気持ち (絶対やばい…絶対やばい…絶対崩れる…) (要素の上に要素を重ねすぎだろ、、、 別ページに分けてくれよ・・・) 10
z-index + position = 怪奇現象 11
怪奇現象 モーダルを突破して来る謎のやつ 12
13
なんで、こんなことが起きたか 14
スクロール固定(position: sticky) z-indexを⾼く設定(スクロールの⼀番⼿前に来る) 疑似コード 15
⼀番⼿前にくるのが、 z-index持ちのTable header 16
<table />&<div />「親に向かってなんだそのz-indexは!」 17
Solution • modalをopen時に、 z-index=0 • modalをopen時に、 stickyを解除 • modalに⾼いz-indexを設定 18
Solution • modalをopen時に、 z-index=0 • modalをopen時に、 stickyを解除 • modalに⾼いz-indexを設定 19
⼦供より親が強くなって解決!!! 20
おしまい 21
22
⼤きいz-indexを使うのは、 親の⽴場として⼤⼈げ無い! 23
z-indexの管理をそもそも したくない!! 24
それ、CSSの標準機能でできます 25
Stack Context 26
そもそもz-indexの数値の意味は? 27
z-indexの数値の意味 要素の重なり順 28
z-indexの数値の意味 同じstack context内での要素の重なり順 29
Stack context z-indexの効果の影響範囲 30
注:どんな要素も<html />要素が作る、 ルートコンテキストに所属する 31
header要素とモーダルは同じルートコンテキストに 所属している => z-indexの⾼い⽅が前にくる 疑似コード 32
突破していしる要素を、 新しいコンテキストで包み、 z-indexの数値が外に漏れないようにする 33
コンテキストの作り⽅ https://developer.mozilla.org/ja/docs/Web/Guide/CS S/Understanding_z_index/The_stacking_context • position: absolute or relative と z-indexを当てる
• position: sticky or fixedを当てる • opacity を1以下にする 34
opacityを設定する 35
36
position: relativeを設定する 37
疑似コード 38
39
Stack contextを上⼿に使えば、 ⼦がどんなz-indexを持っていても、 スタイルの崩れを防げる 40
⼦供がz-indexを使って、⾔うことを聞かないなら、 Stack contextに閉じ込めてやりましょう。 教訓 今⽇のコード: https://github.com/sadnessOjisan/DialogOnModalOnTooltipOnTable 41