[英]HTML/CSS Image grid
I am a back-end developer and I need a little help with some HTML/CSS to replace one large image with multiple small images. 我是一名后端开发人员,我需要一些HTML / CSS的帮助,以将一个大图像替换为多个小图像。 The smaller images should take up the exact same area as the larger image.
较小的图像应占据与较大图像完全相同的区域。 Here's the HTML I have now for the larger image:
这是我现在拥有的用于大图的HTML:
<table border="0" cellspacing="0" cellpadding="0" width="300">
<tr>
<td>
<img src="myimage.jpg" width= "300" height="190" border="0">
</td>
</tr>
</table>
So the above works perfectly to display my large image. 因此,上面的方法非常适合显示我的大图像。 Now I want to replace the img tag with some divs, I think?, and some CSS so that I can place small images by x and y position so that when pieced together occupy the same 300x190 as the large image.
现在,我想用一些div和一些CSS替换img标签,以便可以按x和y位置放置小图像,以便将它们拼在一起时占据与大图像相同的300x190。
For example if I assume that the top left is 0, 0 and x increases as I go to the right and y increases as I go down and I'm placing my images using the x,y of the upper left hand corner. 例如,如果我假设左上角为0,则向右移动时x和0会增加,而当向下移动时,y会增加,并且我会使用左上角的x,y放置图像。 Then I could take two images that are both 150x190 and place the first at 0,0 and the second as 150,0.
然后,我可以拍摄两个均为150x190的图像,并将第一个图像设置为0,0,将第二个图像设置为150,0。
What is the best HTML/CSS for this? 什么是最好的HTML / CSS?
Edit: I need to handle this in an arbitrary sense. 编辑:我需要以任意的方式来处理。 So there couple be a bunch of small images that all have their own x,y as opposed to the simple example above.
因此,有一堆小图像,它们都有自己的x,y,与上面的简单示例相反。
Use absolute
inside relative
positioning. 使用
absolute
内部relative
位置。
See: http://css-tricks.com/absolute-positioning-inside-relative-positioning/ 参见: http : //css-tricks.com/absolute-positioning-inside-relative-positioning/
See: http://jsfiddle.net/zwwwt/ 请参阅: http : //jsfiddle.net/zwwwt/
The inner div
s could just as easily be img
s. 内部
div
可以很容易成为img
。
<div class="imageContainer">
<div style="top: 0; left: 0; width: 100px; height: 50px"></div>
<div style="top: 0; left: 100px; width: 200px; height: 50px"></div>
<div style="top: 50px; left: 0; width: 150px; height: 150px"></div>
<div style="top: 50px; left: 150px; width: 150px; height: 150px"></div>
</div>
.imageContainer {
position: relative;
width: 300px;
height: 200px;
border: 1px solid red
}
.imageContainer div {
position: absolute;
background: #ccc;
outline: 1px dashed #000
}
If your already using a table for this, why not just add more rows/columns to create your 2x2 grid and enter each image in there. 如果您已经为此使用表格,为什么不添加更多行/列来创建2x2网格并在其中输入每个图像。 It would be the fastest solution.
这将是最快的解决方案。
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="myimage1.jpg" width= "150" border="0"></td>
<td><img src="myimage2.jpg" width= "150" border="0"></td>
</tr>
<tr>
<td><img src="myimage3.jpg" width= "150" border="0"></td>
<td><img src="myimage4.jpg" width= "150" border="0"></td>
</tr>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.