実現したいこと
tableで行・列を固定し、スクロールを実現した表をiPhoneで表示した際、テーブルを固定したい。
発生している問題・分からないこと
tableで行・列を固定し、スクロールを実現した表をiPhoneで表示した際、指でホールドして動かすと、それに追従してテーブルが動いてしまいます。
※以下サイトのように「行・列を固定する」をiPhoneで表示した場合、テーブルに指を置いて動かすと、テーブル自体が動いてしまう(スクロールの動きとは別に)。
https://web.runland.co.jp/frontend/post-6084
該当のソースコード
HTML
1<div class="table_box"> 2 <table> 3 <tr> 4 <th class="sticky_cross">絶対固定</th> 5 <th class="sticky_col">行固定</th> 6 <th class="sticky_col">行固定</th> 7 <th class="sticky_col">行固定</th> 8 <th class="sticky_col">行固定</th> 9 <th class="sticky_col">行固定</th> 10 </tr> 11 <tr> 12 <th class="sticky_row">列固定</th> 13 <td>テキスト</td> 14 <td>テキスト</td> 15 <td>テキスト</td> 16 <td>テキスト</td> 17 <td>テキスト</td> 18 </tr> 19 <tr> 20 <th class="sticky_row">列固定</th> 21 <td>テキスト</td> 22 <td>テキスト</td> 23 <td>テキスト</td> 24 <td>テキスト</td> 25 <td>テキスト</td> 26 </tr> 27 <tr> 28 <th class="sticky_row">列固定</th> 29 <td>テキスト</td> 30 <td>テキスト</td> 31 <td>テキスト</td> 32 <td>テキスト</td> 33 <td>テキスト</td> 34 </tr> 35 <tr> 36 <th class="sticky_row">列固定</th> 37 <td>テキスト</td> 38 <td>テキスト</td> 39 <td>テキスト</td> 40 <td>テキスト</td> 41 <td>テキスト</td> 42 </tr> 43 </table> 44</div> 45
CSS
1.table_box{ 2 max-width: 300px; 3 height: 300px; 4 overflow-x: auto; 5 overflow-y: auto; 6 -webkit-overflow-scrolling: touch; 7} 8table { 9 border-collapse: collapse; 10 border-spacing: 0; 11 width: 100%; 12} 13th, td { 14 vertical-align: middle; 15 padding: 20px; 16 border: 1px solid #000; 17 color: #000; 18 font-size: 14px; 19 text-align: center; 20 white-space: nowrap; 21} 22th { 23 background: #ccc; 24} 25td { 26 background: #fff; 27} 28.sticky_row { 29 position: sticky; 30 top: 0; 31 left: 0; 32 background: none; 33 border-left: none; 34 border-right: none; 35} 36.sticky_row::before { 37 content: ""; 38 position: absolute; 39 top: 0; 40 left: 0; 41 width: 100%; 42 height: 100%; 43 border-left: 1px solid #000; 44 border-right: 1px solid #000; 45 background: #ccc; 46 z-index: -1; 47} 48.sticky_col { 49 position: sticky; 50 top: 0; 51 left: 0; 52 background: none; 53 border-top: none; 54 border-bottom: none; 55} 56.sticky_col::before { 57 content: ""; 58 position: absolute; 59 top: 0; 60 left: 0; 61 width: 100%; 62 height: 100%; 63 border-top: 1px solid #000; 64 border-bottom: 1px solid #000; 65 background: #ccc; 66 z-index: -1; 67} 68.sticky_cross { 69 position: sticky; 70 top: 0; 71 left: 0; 72 background: none; 73 border-top: none; 74 border-bottom: none; 75 border-left: none; 76 border-right: none; 77 z-index: 1; 78} 79.sticky_cross::before { 80 content: ""; 81 position: absolute; 82 top: 0; 83 left: 0; 84 width: 100%; 85 height: 100%; 86 border-top: 1px solid #000; 87 border-bottom: 1px solid #000; 88 border-left: 1px solid #000; 89 border-right: 1px solid #000; 90 background: #ccc; 91 z-index: -1; 92}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
googleなどで検索しましたが、当該質問の回答
補足
特になし

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2024/03/20 04:30
2024/03/20 06:11
2024/03/20 17:10
2024/03/20 22:29
2024/03/21 02:13