在怪异模式下,是否可以将 img 的大小调整为其包含的表格单元格?
这似乎是过去的一次爆炸,但由于项目限制,我陷入了怪癖模式和表格......
我正在处理的表格在每个单元格中都有一个图像,其中所有单元格应该具有相同的大小。表的宽度和高度设置为父容器的百分比。
问题是图像不会缩小,无论我做什么,它们似乎都保持原始大小。然后,表格不符合其设置的大小,它已调整大小以容纳所有图像。在标准模式下,我相信图像上的“宽度:100%”更接近我想要实现的目标。
我正在考虑一个 javascript 解决方案,它循环遍历每个图像,计算它们的大小应该是什么并手动调整大小。但这可能会在开始时导致一些加载时间,这并不理想。
编辑:
我在JSBin编写了一个基本示例。我想要实现的是能够设置表格的大小并调整图像的大小,无论是增大还是缩小到单元格。
第四个 jsbin 修订版使用虚拟图像。
This may seem like a blast from the past but due to project constraints I am stuck with quirks mode and tables...
The tables that i'm dealing with have a single image in each cell where all the cells should be the same size. The tables width and height are set as percentages of a parent container.
The problem is the images don't resize down, they stay at their original size seemingly no matter what I do. Then the table doesn't adhere to its set size, it has resized to hold all of the images. In standards mode I believe 'width: 100%' on the image gets closer to what I want to achieve.
I'm considering a javascript solution which loops over each image calculating what their size should be and resizing manually. But this is probably going to cause a bit of a loading time at the start which isn't ideal.
Edit:
I have written a basic example at JSBin. What I want to achieve is to be able to set the size of the table and have the images resize, whether growing or shrinking to their cell.
The 4th jsbin revision uses the dummy images.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为我已经解决了这个问题。
我已经在 Chrome、Firefox、Internet Explorer、Safari、Opera 中测试了这个演示;它们都一致地呈现。
div
。我知道这不太好,但必须这样做才能使其在 Chrome 中工作。table-layout:fixed
以使其在 Internet Explorer 中正常工作。现场演示
CSS:
HTML:
I think I've solved this.
I've tested this demo in Chrome, Firefox, Internet Explorer, Safari, Opera; they all render consistently.
div
in each cell. I know this isn't awesome, but it had to be done to make it work in Chrome.table-layout: fixed
to make it work in Internet Explorer.Live Demo
CSS:
HTML:
我已经通过 JavaScript 解决了我的问题。我找不到一种方法可以让所有浏览器都能正常运行而不强制它们。
我基本上循环遍历每个图像,检查其父表的大小应该是多少,然后除以行数以找到图像高度,并除以列数以获得宽度。
I have solved my problem via JavaScript. I couldn't find a way to make all the browsers play nice without forcing them.
I basically loop over each image checking what their parent tables size was supposed to be, then divide that by the number of rows to find the image height and by columns for width.