简体   繁体   English

固定居中div的无重复背景图片?

[英]Fixed no-repeat background image in centered div?

I've got a fixed-width centered div with a fixed no-repeat background image in it, and the background image needs to be off-centered. 我有一个固定宽度的居中div,其中有一个固定的无重复背景图像,并且背景图像需要偏离中心。 However, when the window is resized, whether the image is fixed using percentage or pixel coordinates, it does not stay positioned correctly within the div. 但是,调整窗口大小时,无论是使用百分比坐标还是像素坐标固定图像,它都不会在div内正确定位。

Is there a way to either: 1) fix a background image to its div rather than the page, or 2) use a similar hack to the "left:50%; margin-left:/ $twice-the-pixel-size-of-div-width /;" 有没有一种方法可以:1)将背景图片固定在其div而不是页面上,或者2)对“ left:50%; margin-left:/ $ twice-the-pixel-size- of-div-width /;“ div centering hack to get the fixed background image to stay at the same spot in the centered div when the page is resized? div居中hack,以使固定的背景图像在调整页面大小时保持居中div中的相同位置?

Is the background-position property what you're looking for? 您正在寻找背景位置属性吗?

http://www.w3schools.com/cssref/pr_background-position.asp http://www.w3schools.com/cssref/pr_background-position.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM