如何将响应图像与表格并排对齐



我在右边有一个表,我想在左边有一个图像与表对齐。问题是,当调整页面大小时,图像大小不符合表格。

.div-contains{
background-image: url("http://www.castan.pt/castan/wp-content/uploads/2014/07/img-teste-02.jpg");
position: relative;
background-repeat: no-repeat;
background-size: 100%;
}
.div-forum{
overflow-x:auto;
background-color:white;
width:75%;
}
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr{
border-bottom: 1px solid #ddd;
}
<!DOCTYPE html>
<html>
<head>
<style>

</style>
</head>
<body>
<div class="div-contains" >
<div class="div-forum" >
<table>
<tbody>
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

我想有表和图像并排,当有人调整屏幕大小都有相同的大小。https://i.stack.imgur.com/bFkXr.png

如果你必须将图像设置为背景,并将其设置在右边,你可以这样做:

在你的div-contains中设置这个属性:

background-size: 25%; /* From a 100% set 25% as your table width take 75% */
background-position: right; /* set it to the right */

演示

.div-contains{
background-image: url("http://www.castan.pt/castan/wp-content/uploads/2014/07/img-teste-02.jpg");
position: relative;
background-repeat: no-repeat;
background-size: 25%; /* From a 100% set 25% as your table width take 75% */
background-position: right; /* set it to the right */
}
.div-forum{
overflow-x:auto;
background-color:white;
width:75%;
}
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr{
border-bottom: 1px solid #ddd;
}
<!DOCTYPE html>
<html>
<head></head>
<body>
<div class="div-contains" >
<div class="div-forum" >
<table>
<tbody>
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>yrdyr</td>
<td>yrdyr</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

最新更新