我只想要我的主页 div 的背景图像,它只对台式机和平板电脑(横向)可见。我可以使用 CSS 媒体查询来调整它们。
但是我的背景图片不适合全高。
这是我的pluner代码。 http://plnkr.co/edit/HzlZdqvprkhzO1edqNKK?p=preview
我的 jquery 代码
$(document).ready(function(){
console.log($('.home').height());
});
也返回 null。
解决这个问题的最佳方法是什么。
最佳答案
将这段代码添加到你的图像中,你将在没有 jquery 的情况下得到你的结果:
background: url(http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg) no-repeat center center fixed;
background-size: cover;
height: 400px;
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
secret 是使用 background-size: cover 然后将背景设置为固定高度和宽度 100%
关于css - 使用 css 或 jquery 将背景图像设置为全高和全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28559845/