相对于图像定位块
我有以下情况:
- 我有一个固定大小的容器。
- 在容器内,我显示一个比容器大的图像(大小未知)。我想显示尽可能大的图像(但保持纵横比)。我还希望图像在容器中垂直和水平居中(到目前为止一切都很好,我知道该怎么做)
- 现在我想在图像上有两个覆盖层(大小未知):一个与顶部对齐,一个与顶部对齐图像的底部。
我无法正确理解最后一点。如果不清楚,那么希望 这个演示 应该有所帮助:我的叠加层与 < 的顶部/底部对齐em>容器。相反,我希望它们与图像对齐。任何帮助表示赞赏!
I have the following situation:
- I have a container of a fixed size.
- Inside the container I display an image (of unknown size) that is bigger than the container. I want to display the image as big as possible (but keeping the aspect ratio). I also want the image to be vertically and horizontally centered in the container (so far so good, I know how do that)
- Now I want to have two overlays (of unknown size) over the image: one aligned with the top and one with the bottom of the image.
I cannot get the last point right. If it's unclear then hopefully this demo should help: there I have the overlays aligned with top/bottom of the container. Instead I want them aligned with the image. Any help appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
position:relative
不适用于表格单元格。从规范: http://www.w3.org/TR/CSS21 /visuren.html#propdef-position
因此,添加一个包装器
div
并对其应用position:relative
:http://jsfiddle.net/B9Le8/5/
position: relative
does not work on table cells.From the spec: http://www.w3.org/TR/CSS21/visuren.html#propdef-position
So, add a wrapper
div
and applyposition: relative
to that instead:http://jsfiddle.net/B9Le8/5/
我认为你应该将图像放在
中并在其中设置
style="background:url()"
。然后在该DIV
中,放入您想要定位的DIV
。这样应该更容易。I think you should put the image in a
<DIV>
and set astyle="background:url()"
in it. Then in thatDIV
, put theDIV
s that you want to position. It should be easier like that.