0

I would like to display checkbox instead of image (image must be hidden in every row). Another problem is that height of the space reserved for the image must be same as image, but width must be 30px (height of the image is dynamic, so I don't know it). It would be ideal if checkbox is in the center of the space reserved for the image. Is it possible to do this?

Here is example and code:

<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>

2
  • So why don't you use <input type="checkbox"> ? Commented Feb 26, 2017 at 4:34
  • Sorry, I can not understand what do you mean by image height must be kept? You want the height of a table cell must be the height of original image? Commented Feb 26, 2017 at 4:49

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

Is it possible to achieve the same result if all DIV's are in the same cell? only one row, one cell ?
the same css @FrenkyB
If you find time and check my other question. It is not the same, because all elements are in the same cell, not in different rows.
jsfiddle.net/MoazW/sa694nvd/1 or jsfiddle.net/MoazW/wjLguLkm ( Is it possible to achieve the same result if all DIV's are in the same cell? only one row, one cell ?) all divs in one <td> @FrenkyB
1

If I understand your question, you want a CSS rule like that:

    img {
      position: absolute;
      width: 30px;
      visibility: hidden;
    }
<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.