[英]How do I add add 2 arrow each, one top arrow button and one bottom arrow button to my react table crud connected to my sql?
body characters at least 30 chars正文字符至少 30 个字符
You can create an icon and then transform: rotate
it using a class.您可以创建一个图标然后transform: rotate
它。 Then set you elements items using positioning .然后使用定位设置元素项。
Embed the icons in the parent element and then set the parent to position: relative
then on the arrows, set their position:absolute
and then set their left and top positions relative to the parent element.将图标嵌入到父元素中,然后将父元素设置为position: relative
然后在箭头上,设置它们的position:absolute
然后设置它们相对于父元素的左侧和顶部位置。
For the JS, use a loop on the arrow class and then check classList
for up or down , use the event.target
to get the element being clicked.对于 JS,在箭头 class 上使用循环,然后检查classList
的up或down ,使用event.target
获取被点击的元素。
I use a dataset on the parentNode to show that the event.target
is working.我使用parentNode上的数据集来显示event.target
正在工作。
const arrows = document.querySelectorAll('.arrow') function upDown(e) { if (e.target.classList.contains('up')) { console.log('up', e.target.parentNode.dataset.id) } if (e.target.classList.contains('down')) { console.log('down', e.target.parentNode.dataset.id) } } arrows.forEach(arrow => { arrow.addEventListener('click', upDown) })
body { margin: 0; padding:0; } table { width: 100vw; } th { border: solid 2px black; padding-left: 1rem; position: relative; font-family: sans-serif; } th:nth-of-type(2){ width: 9rem; }.arrow { border: solid black; border-width: 0 2.5px 2.5px 0; display: inline-block; padding: 2.5px; }.up { transform: rotate(-135deg); -webkit-transform: rotate(-135deg); position: absolute; left: 9rem; top: .2rem; cursor: pointer; }.up:hover { border: solid red; border-width: 0 2px 2px 0; display: inline-block; padding: 2.5px; }.down { transform: rotate(45deg); -webkit-transform: rotate(45deg); position: absolute; left: 9rem; bottom: .2rem; cursor: pointer; }.down:hover { border: solid red; border-width: 0 2.5px 2.5px 0; display: inline-block; padding: 2.5px; }
<table> <tr> <th>Contact 1 info: John Doe</th> <th class="cont" data-id="John Doe">Contacted 1 <i class="arrow up"></i> <i class="arrow down"></i> </th> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.