html - 图片太大时设置表格宽度

标签 html css css-tables

我希望我的表格宽度为屏幕的 80%。

该表有 1 行 4 列。 每个单元格包含一个图像。

问题是图片太大了—— 我希望它们的宽度由表格宽度均匀地决定 (每个单元格将占据屏幕的 20%)

这样每张图片的高度将由其宽度决定..

我该怎么做?

最佳答案

这提供了一个简单、优雅且完全响应的解决方案:

HTML:

<table border="1px solid black" width="80%">
    <tbody>
        <tr>
            <td><img src="https://www.cia.gov/library/publications/the-world-factbook/graphics/flags/large/uk-lgflag.gif" width="100%"></td>
            <td><img src="https://www.cia.gov/library/publications/the-world-factbook/graphics/flags/large/uk-lgflag.gif" width="100%"></td>
            <td><img src="https://www.cia.gov/library/publications/the-world-factbook/graphics/flags/large/uk-lgflag.gif" width="100%"></td>
            <td><img src="https://www.cia.gov/library/publications/the-world-factbook/graphics/flags/large/uk-lgflag.gif" width="100%"></td>
        </tr>
    </tbody>
</table>

查看此 jsFiddle example

同样,看这个CSS solution使用

td img {
    width: 100%
}​

关于html - 图片太大时设置表格宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10001928/

相关文章:

php - HTML5 视频播放列表 - 来自 MYSQL 的文件名

html - CSS 导航栏在移动设备上运行缓慢

html - 当用户将鼠标悬停在 div 上时使光标不可见

Firefox 和 IE 中的 jQuery UI 可调整大小错误(?)

jquery - 为什么我在 IE8/IE9 中看不到这个子导航?切换到显示 block 不显示它

javascript - 使用 getElementsByClassName 触发显示

css - 如何..中间的三个 div 在中心以及是否调整导航器的大小

html - 单击鼠标时将文本与光标一起拖动

html - jquery 如何将子 div 动画化到父 div 的右侧?

html - 表格单元格底部的白色边距/填充