繁体   English   中英

保持背景图片居中

[英]keep background image centered

好的,所以我试图模仿Google的首页。 看起来,即使是较小的图片,Google也会对其进行拉伸以适应并且不会过多填充。 我尝试使用背景位置,但它对于某些图像可能看起来不错,但对于其他图像看起来像胡扯。 所以我的问题是,如何使用jQuery来解决这个问题?

好的,这是我正在使用atm的CSS

background-repeat: no-repeat;
background-size: auto;
background-clip: border-box;
background-origin: padding-box; 
background-attachment:scroll; 
background-position: 0px 28%;
position: fixed;
z-index:-10;

页面中的div和div样式,其中使用上述css类作为其打开样式以在背景中显示图像

<div style="display: block; opacity: 0.99999; width: 1600px; height: auto; left: 0px; right: 0px; top: 0px; bottom: 0px; background-image: url(<?php echo base64_decode($_COOKIE['phx_utmc_session']); ?>);" id="phx_utmc_background"></div>

在div部分中使用width作为高度可能会存在一些问题,但是我不确定,因为没有高度将无法正常工作。

所以^^

如前所述,这可以通过CSS完成

尝试

body {
   background: url('http://placekitten.com/200/300');
   background-position: center 0%;
   background-repeat: no-repeat;
}

实时链接

您是否尝试过仅使用CSS

body {
   background: url('background.png') no-repeat center right 40% 0 transparent;
}

尽管我还没有测试过,但是看来您可以使用CSS来完成。

暂无
暂无

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

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