CSS 和不同尺寸的显示器?
我正在做一个网站(WIP)。我遇到了一些CSS问题,希望大家能帮助我。
我目前的情况:
- 我有一张图像,我们将其命名为“bg.png”,宽度约为2500px,背景图像的中心有我的徽标。
- 我的网站应该针对所有尺寸(从小 800 x 600 到 2400 x XXX)用户。
我的问题:
- 如何居中背景图像(bg.png),以便徽标始终位于不同尺寸的显示器屏幕的中心(水平)?
I am doing a website (WIP). I encountered some CSS problems, hope you guys can help me.
My current situation:
- I have am image, lets called it "bg.png" with the width about 2500px, and at the center of the background image has my logo.
- My website should target all size (from small 800 x 600 to 2400 x XXX) users.
My problems:
- How do I centralize the background image(bg.png), so that the logo always positioned in the centered(horizontally) of different size of monitors screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这会将全尺寸图像放置在页面中央,用户将在浏览器窗口允许的范围内看到尽可能多的背景图像。
This will place the image at full-size at the center of the page, and the user will see as much of this background image as their browser window permits.
它可能不适用于 Internet Explorer,但您可以使用position:absolute的一点技巧,如上所述
It probably don't work on Internet Explorer, but you can use a little hack with position: absolute, as above
当您将 img 元素放入另一个盒子时,此解决方案是必要的。但要小心 - 它可能会改变父母盒子的大小。
This solution is necessary, when you put img element onto another box. But be careful - it might change size of parent's box.
如果它只是一个徽标文件,您可以使用
If it was just a logo file you could use