停止表格单元格重叠的HTML CSS

时间:2019-06-03 16:29:20

标签: html css css-tables

我试图建立一个响应表,其中每个单元格都包含一个图像,但是使用我拥有的代码,单元格就会重叠。

宽度设置为100%而不是固定宽度,所以不确定为什么会这样吗?我的代码如下:

.infocard {
  position: relative;
  width: 100%;
  height: auto;
}

.infocard img {
  position: absolute;
  width: 100%;
}

.infocard .infocardimage {
  z-index: 9999;
  transition: opacity .5s ease;
  cursor: pointer;
}

.infocard:hover .infocardimage {
  opacity: 0;
}

.tableproperties {
  width: 100%;
  height: 50%;
}
<table class="tableproperties">
  <tbody>
    <tr>
      <td>
        <div class="infocard">
          <img alt="" class="infocardimage" src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" />
          <img alt="" class="infocardoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
        </div>
      </td>
      <td>
        <div class="infocard">
          <img alt="" class="infocardimage" src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" />
          <img alt="" class="infocardoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
        </div>
      </td>
    </tr>
    <tr>
      <td>
        <div class="infocard">
          <img alt="" class="infocardimage" src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" />
          <img alt="" class="infocardoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
        </div>
      </td>
      <td>
        <div class="infocard">
          <img alt="" class="infocardimage" src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" />
          <img alt="" class="infocardoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
        </div>
      </td>
      <td>
    </tr>
  </tbody>
</table>

我需要在调整屏幕大小时各行不重叠,并且在缩小屏幕时不使这些间隙变大。

1 个答案:

答案 0 :(得分:1)

解决方案是将img + img选择器以及随附的html添加到css中:

var count = {
        'Single User': {
            Windows: {
                OneDrive: 0,
                Teams: 0
            },
            Mac: {
                OneDrive: 0,
                Teams: 0
            }
        },
        Team: {
            Both: {
                OneDrive: 0,
                Teams: 0
            }
        }
    };

for (let { RequestType, ComputerType, ApplicationType } of items) {
    count[RequestType][ComputerType][ApplicationType]++;
}
*{
  box-sizing:border-box;
}
.card {
  float: left;
  width: 33.33%;
  padding: 5px;
  position:relative;
}

/* Clearfix (clear floats) */
.row::after {
  content: "";
  clear: both;
  display: table;
}
.imageoverlay{
  display:none;
  position:absolute;
  left:0;
  top:0;
  width:100%;
  padding: 5px;
}
.card:hover img + img{
  display:block;
  
}