如何在偏移 div 的中心覆盖图像?
我希望能够将一些图标集中在横幅上,该横幅位于已偏移的 div 中间。我不能使用绝对定位,因为它会将其居中但不会偏移。我怎样才能实现这一目标?
I want to be able to center some icons over a banner which is in the middle of a div that has been ofset. I can't use absolute positioning as it would center it but not ofset it. How would I be able to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能
margin: auto;
有效吗?或者您还需要垂直居中吗?编辑:
也许是这样的:
这显示了两个图像在顶部 div 的中心,但它并不漂亮(代码方面,我认为)。
might
margin: auto;
work? Or do you need vertical centering as well?EDIT:
Maybe something along the lines of:
This shows both images over one another centered in the top div, but it's not pretty (code-wise, imo).
您需要将两者设置为绝对位置
外部 div 需要是相对的
还有外部 div 应该设置宽度(这样当您为图像容器指定完整宽度时,它会将其对齐到中间(因为您将 text-align: center 设置为需要居中的 div))。
每个图像都需要位于自己的 div 中,并具有绝对位置(z 顺序与代码中的相同,后面的图像位于顶部)。
代码:
示例:http://jsfiddle.net/Y9PhP/
you need to set both to an absolute position
the outter div needs to be relative
also the outter div should have a width set (this way when you specify a full width to the image's container, it will align it to the middle (because you set a text-align: center to the div you need centered)).
every image needs to be in its own div with an absolute position (the z order is as it is in the code, the one after will be on top).
code:
example: http://jsfiddle.net/Y9PhP/
杰克乔是对的。
您还可以使用
style="position:absolute; top:10000px"
来调整重叠图像的高度。jackJoe is right.
you can also use
style="position: absolute; top:10000px"
to adjust the height of the overlapping image.