javascript - 在 div、td 元素上覆盖 div "edit image"

标签 javascript html

我在可编辑的表格中有一个 div 元素或 td 元素,即您单击该元素,然后弹出窗口允许您编辑文本。我希望能够在可编辑元素的左上角添加一个“编辑图像”。目前,我所拥有的只是当您滚动元素时,背景变为黄色以指示。想要弹出更好的图像。尝试使用绝对 div,但不确定我的样式设置是否正确,因为它无法正常工作。

<td>
   <div style="position:absolute; display:inline"><img src="/edit.png"/></div>
   <p>This would be the normal text that is editable</p>
</td>

我会在翻转时使用 jQuery 添加 div,并带有一个前缀。

最佳答案

将您的“编辑图像”放在内容之后,这样它就会出现在实际内容之上(源代码中后面出现的元素具有更高的 z-index:

HTML

<td>
   <div class="editable">
      <p>This would be the normal text that is editable</p>
      <img class="editimg" src="/edit.png"/>
   </div>
</td>

CSS

div.editable {
   width:100%;
   position:relative; /* this allows the img to be positioned relative to the div */
}
div.editable img.editimg {
   position:absolute;
   top:5px;
   right:5px;
}

关于javascript - 在 div、td 元素上覆盖 div "edit image",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/908637/

相关文章:

javascript - 使用谷歌分析跟踪链接点击?

javascript - 为什么单独依赖作用域链并避免在 Javascript 中显式引用 head 对象是有益的?

javascript - 如何在Javascript中使用子例程?

javascript - Bootstrap 导航栏不会在移动设备上崩溃

javascript - 默认选择第一个单选按钮

html - CSS 表格 'borrows' 来自另一个表格的样式

javascript - 获取html输入标签值

javascript - 下划线数组理解?

html - @font-face 与 cufon

javascript - 将此功能从童年时代转换为更好的东西?