実現したいこと
<table>
のセルの中で、「文字a
」のすぐ横に「要素.triangle
」を置きたいです。
発生している問題
「要素.triangle
」が「文字a
」のすぐ横でなく、セルの右端にいってしまいます。
該当のソースコード
よろしければお試しください。
https://jsfiddle.net/9u1rqt74/
このリンクのコードは次の通りです。
html
1<table> 2 <thead> 3 <tr> 4 <th class="a">a<div class="triangle"></div></th> 5 <th class="b">b</th> 6 </tr> 7 </thead> 8 <tbody> 9 <tr> 10 <td>あ</td> 11 <td>い</td> 12 </tr> 13 <tr> 14 <td>う</td> 15 <td>え</td> 16 </tr> 17 </tbody> 18</table>
css
1/*ソートの三角*/ 2.triangle { 3 clip-path: polygon(0 0, 100% 0%, 50% 100%); 4 width: 13px; 5 height: 9px; 6 right: 3px; 7 position: absolute; 8 background: red; 9 top: calc(50% - 4px); 10} 11 12/*テーブル*/ 13table { 14 border-collapse: collapse; 15 width: 100%; 16} 17 18/*ソートの三角のための調整*/ 19th { 20 padding-right: 20px !important; 21 cursor: pointer; 22} 23 24/*ボーダー*/ 25th, 26td { 27 position: relative; 28} 29th:after, 30td:after { 31 border-right: 1px dotted #888; 32 position: absolute; 33 inset: 0 0 0 0; 34 content: ''; 35 pointer-events: none; 36} 37 38/*文字を真ん中*/ 39th { 40 text-align: center; 41} 42 43/*行の色*/ 44thead th { 45 background: #DDDDDD; 46} 47tbody tr:nth-child(odd) > * { 48 background: #F0F0F1; 49}
試したこと
position: absolute;
を解除し、flot: right
にしてみましたが、.triangle
の高さが真ん中にきてくれません。
css
1.triangle { 2 /* position: absolute; */ 3 float: right; 4}
position: absolute;
を解除し、th.a
をdisplay: flex
にすればできましたが、やはりdisplay: table-cell;
は解除したくありません。
css
1.triangle { 2 /* position: absolute; */ 3} 4th.a { 5 display: flex; 6 align-items: center; 7 justify-content: center; 8}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/16 01:30 編集
2022/07/16 01:31
2022/07/16 02:59
2022/07/16 06:11