html - 显示复选框而不是图像

标签 html css

我想显示 checkbox 而不是图像(图像必须隐藏在每一行中)。另一个问题是图片预留空间的height必须和图片一样,但是width必须是30px(图片的高度是动态的,所以我不知道)。如果复选框位于为图像保留的空间的中心,那将是理想的。可以这样做吗?

Here是示例和代码:

<table>
  <thead>
    <th>Image</th>
  </thead>
  <tr>
    <td><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></td>
  </tr>
  <tr>
    <td><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></td>
  </tr>
  <tr>
    <td><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></td>
  </tr>
  <tr>
    <td><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></td>
  </tr>
  <tr>
    <td><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></td>
  </tr>
</table>

最佳答案

jsfiddle

CSS

img{
    /*opacity: 0; adjust the opacity to show or hide the img*/
    visibility: hidden;  /* @Marcos Silva */

}
.img_con{
    position: relative;
    width: 30px;
    overflow-x: hidden;
}
input{
    position: absolute;
    left: 0;
    top:0;
    right: 0;
    bottom:0;
    margin: 0 auto;
    margin-top: 100%
}

HTML

<table>
  <thead><th>Image</th></thead>
  <tr>
    <td><div class="img_con"><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></div></td>
  </tr>
  <tr>
    <td><div class="img_con"><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></div></td>
  </tr>
  <tr>
    <td><div class="img_con"><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></div></td>
  </tr>
  <tr>
    <td><div class="img_con"><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></div></td>
  </tr>
  <tr>
    <td><div class="img_con"><img src='http://i.imgur.com/cddKZVx.jpg'><input type='checkbox'></div></td>
  </tr>
</table>

关于html - 显示复选框而不是图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42464749/

相关文章:

javascript - Twitter Bootstrap Modal 是黑暗的吗?

jQuery Frozen DIv 标题在通知栏中淡入淡出

javascript - 如何更改输入框光标颜色?

css - 把cufon加粗

animation - CSS3 背景渐变动画 - background-size :cover not working?

html - IE9 中的负边距和 float

javascript - 在 HTML 中分配 XML-AJAX 响应

css - LESS:如何使用嵌套指定当前标签?

html - 如何根据内容强制容器扩展高度

javascript - 在目录中导入整个文件