阻止 table 个单元格重叠 HTML CSS
Stop table cells from overlapping HTML CSS
我正在尝试设置响应式 table,其中每个单元格都包含一个图像,但使用我的代码,单元格重叠。
宽度设置为 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>
我需要在调整屏幕大小时行不重叠,并且在屏幕变小时间隙不会变大。
解决方案是将 img + img 选择器添加到 css 以及随附的 html:
*{
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;
}
<div class="row">
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Snow" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
</div>
<div class="row">
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Snow" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
</div>
我正在尝试设置响应式 table,其中每个单元格都包含一个图像,但使用我的代码,单元格重叠。
宽度设置为 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>
我需要在调整屏幕大小时行不重叠,并且在屏幕变小时间隙不会变大。
解决方案是将 img + img 选择器添加到 css 以及随附的 html:
*{
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;
}
<div class="row">
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Snow" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
</div>
<div class="row">
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Snow" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
<div class="card">
<img src="https://animatedanatomy.com/images/16-9-dummy-image6.jpg" alt="Forest" style="width:100%">
<img class="imageoverlay" src="http://barricadeprinters.com/wp-content/uploads/2018/10/16-9placeholder.png" />
</div>
</div>