html - 自动调整为 100% 宽度保持纵横比的表格的图像背景

标签 html css html-table background-image

我在使用背景图片时遇到问题。

我需要背景图像填充 div 容器的 100% 宽度并自动完成高度以保持其纵横比。

#pitch{background-color:d9ffd9;background:url('https://conceptdraw.com/a2048c3/p1/preview/640/pict--sport-field-plan-template-sport-field-plan---template.png--diagram-flowchart-example.png');background-position: top center;background-repeat: no-repeat;background-size: 100%,100%;}
<div id="pitch-container">
<table id="pitch" width="100%">
<tr>
<td><img class="player-icon" src="https://www.freeiconspng.com/minicovers/sports-football-2-icon-12.png"><br>Player</td>
</tr>
</table>
</div>

结果:

最佳答案

要解决这个问题,您唯一要做的就是将图像的宽度设置为 100%。 保持您的 HTML 不变,您的 CSS 应该类似于:

.player-icon
{
   width : 100%;
}

这一定能解决您的问题。

关于html - 自动调整为 100% 宽度保持纵横比的表格的图像背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54133463/

相关文章:

html - 在网站底部设置页脚

javascript - 当我将 JavaScript 元素添加到我的 SVG 文件时,它消失了

css - Gmail 如何隐藏他们的主题行溢出?

html - 在所有移动设备中的横幅图像中心显示文本

html - 我无法正确定位导航栏中的某个元素

javascript - 通过 click() 检索 jQuery 中 div 的属性值

javascript - HTML 5 地理定位 watchPosition

css - 删除表格单元格和行之间的间距

javascript - 默认情况下以折叠方式开始 HTML 行

javascript - jQuery CSV 插件不会将行拆分为数组的数组