[英]css - how to stretch a background image across the entire window
我在尝试拉伸整个窗口时遇到的背景图像有问题。 外部CSS如下:
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("mybackground.jpg"); -webkit-background-size: cover; background-repeat: no-repeat; background-size: 70%;}
@font-face /* support for browsers & IE v10 onwards*/
{
font-family:homefont; src: url("font3.ttf");
}
#main
{
position:absolute;
left:450px;
top:30px;
font-family: homefont;
font-size:150px;
line-height:70%;
}
这就是我所拥有的(请参阅浏览器窗口右侧的空白区域):
谁能告诉我如何在整个窗口拉伸图像?
我已按照评论中的建议尝试了建议,但是图像似乎是从我的膝盖向下切割的:(。还有其他建议吗?
这是一篇关于你的css-tricks问题的axcellecnt文章
令人敬畏,简单,进步的CSS3方式:
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
你可以试试这个
background-size: 100%;
要么
background-size:cover
干得好:
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
适用于:
Safari 3+
Chrome
IE 9+
Opera 10+ (Opera 9.5 supported background-size but not the keywords)
Firefox 3.6+ (Firefox 4 supports non-vendor prefixed version)
top center;background-size-110%;background-repeat- no-repeat
请根据需要增加尺寸。
您需要将background-size
属性与值cover
一起使用,如下所示
body {
background-image: url("mybackground.jpg");
background-repeat: no-repeat;
background-size: cover;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.