简体   繁体   English

调整大小<tr>和<td>图像内按百分比

[英]Resize <tr> and <td> with image inside by percent

I have this table:我有这张桌子:

<table>
    <tr>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
    </tr>
    <tr>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
    </tr>
    <tr>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
    </tr>
    <tr>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
        <td><img src="..."/></td>
    </tr>
    ...
</table>

Every image has a different size and is huge.每个图像都有不同的大小,而且很大。

Right now, I see them like this:现在,我看到他们是这样的:

This is the view:
----------------------------------------
| This is the table:                   |
| -------------------------------------|------------------
| |             |             |        |     |           |
| |             |             |        |     |           |
| |             |             |        |     |           |
| |    img1     |     img2    |     img|3    |    img4   |
| |             |             |        |     |           |
| |             |             |        |     |           |
| |             |             |        |     |           |
| |             |             |        |     |           |
| |------------------------------------|-----------------|
| |             |             |        |     |           |
---------------------------------------      |           |
  |             |             |              |           |
  |             |             |              |           |
  |     img5    |     img6    |      img7    |    img8   |
  |             |             |              |           |
  |             |             |              |           |
  |             |             |              |           |
  --------------------------------------------------------

                       ...and so on...

I want to fit the width of table into view.我想使表格的宽度适合视图。

I want to set the width of every <td> to 25% and and every <tr> to 50%.我想将每个<td>width设置为 25%,并将每个<tr>width设置为 50%。 As result, to see 8 images in view.结果,在视图中看到 8 个图像。

The table has more <tr> , but I want to can complete see 2 <tr> at once.该表有更多<tr> ,但我想一次完成看到 2 个<tr>

For the width you can set table to width 100% and td width 25%;对于宽度,您可以将表格设置为宽度 100% 和 td 宽度 25%; https://codepen.io/rohinikumar4073/pen/gOMrELb https://codepen.io/rohinikumar4073/pen/gOMrELb

 td { width: 25%; } table { width: 100%; table-layout: fixed; } td img { width: 100%; }
 <table> <tr> <td><img src="https://via.placeholder.com/450" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> </tr> <tr> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> </tr> <tr> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> </tr> <tr> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> <td><img src="https://via.placeholder.com/150" /></td> </tr> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM