在 css 上显示大背景图像的好方法是什么
我问了一个关于此的问题针对我的代码,人们确实很有帮助,所以我选择了更成功的答案,即使我没有解决我的问题。
- 我试图获得一个大的 css 背景,就像 livingsocial 那样。
- 我的图像尺寸为 1400 x 1050
- 我当前的分辨率是:1280 X 1024
- 我的图像总是从底部被切断
问题: 使用 css 显示大图像背景的最佳方法是什么?
- 我是否需要有 4 种不同分辨率的相同背景图像,然后使用最适合用户当前使用的分辨率的图像(是否有一些脚本)?
- 我是否只需要一张使用 css 不断缩放的大图像,
- 其他人是如何解决这个问题的?
我有兴趣知道执行此操作的最佳方法是什么,以便它在上述三个选项的所有分辨率下都能正常工作。
I asked a question about this that was specific to my code and people were really helpful, so I picked the answer that was more susccessful, even though I did not solve my problem.
- I am trying to get a large css background just like livingsocial has.
- I have an image that is 1400 x 1050
- My current resolution is: 1280 X 1024
- My image keeps getting cut off from the bottom
Question(s):
Whats the best way to display large image backgrounds using css?
- Do I need to have same background image in 4 different resolution and then use the image that best fits the current resolution user is using (is there some script for it)?
- Do I need just one big image that I keep scaling using css
- How are others tackling this problem?
I'm interested in knowing what is the best way to do this so that it works fine in all resolutions out of the three options above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
CSS3解决方案
您可以在 CSS3 中使用
background-origin
和background-size
,但 IE8 及更低版本不支持。PHP解决方案
您可以使用 GD2 来缩放特定于用户浏览器的图像,此解决方案还涉及 JavaScript。
社交生活方式
他们插入带有
标签的图像并将其定位固定。
Living Social 在其
标记上应用了更多代码,但似乎有点多余,也许是为了更好的跨浏览器支持,我没有在此处显示。
CSS3 Solution
You could use
background-origin
andbackground-size
in CSS3, but it's not supported by IE8 and lower.PHP Solution
You could GD2 to scale the image specific to the users browser, this solution would also involve JavaScript.
Living Social Way
They're inserting an image with the
<img/>
tag and positioning it fixed.Living Social has some more code applied to their
<img/>
tag, but it seems sort of redundant, perhaps it's for better cross-browser support, I didn't show it here.我不知道有哪种 CSS 方法可以实现跨浏览器背景..实际上可以在较低的 ie 版本中工作。
然而,有一些 jquery 插件,比如这个:
http://srobbin.com /blog/jquery-plugins/jquery-backstretch/
I am not aware of a CSS method that will achieve crossbrowser background.. that actually works in lower ie versions.
However there are some jquery plugins out there, like this one:
http://srobbin.com/blog/jquery-plugins/jquery-backstretch/
尝试指定 img 的宽度和高度,然后如果它是在图像的两侧进行切割的。否则,您的图像将根据屏幕尺寸被截断;或者拉伸,如果您将其尺寸设置为与屏幕尺寸相匹配。
Try specifying the img width and height, then if it's cut on the sides center the image. Otherwise, your image will be cut off depending on the screen size; Or stretched out, if you set the size of it to match the screen size.
谷歌:CSS自动调整背景图片大小
http://css-tricks.com/3458-perfect-full-页面背景图像/
Google: css autosize background image
http://css-tricks.com/3458-perfect-full-page-background-image/
我决定再次回答这个问题,考虑到不同的要求,两者都是有效的;但是,如果您不希望图像在底部被切断,则此问题专门解决了这一问题。
演示: http://wecodesign.com/demos/stackoverflow-7082174。嗯
I decided to answer this question again, given the different set of requirements, both are valid; however, this one specifically addresses if you DON'T want the image to be cut off at the bottom.
DEMO: http://wecodesign.com/demos/stackoverflow-7082174.htm
我刚刚从生活社交中剥离了代码,并认为如果我把它放在这里会很方便:
这是你的CSS:
当然你需要提供你的background.jpg
I just stripped the code from living social and thought it would be handy if I put it here:
and here is your css:
and of course you need to supply your background.jpg