我正在尝试获取HTML元素(body、div等)的背景图像。以拉伸其整个宽度和高度。
运气不是很好。有没有可能,或者除了背景图像之外,我还需要用其他方式来做吗?
我目前的css是:
body {
background-position: left top;
background-image: url(_images/home.jpg);
background-repeat: no-repeat;
}
提前谢谢。
编辑:我不热衷于维护Gabriel的建议中的CSS,所以我改为更改页面的布局。但这似乎是最好的答案,所以我将其标记为。
发布于 2011-03-17 04:21:03
<style>
{ margin: 0; padding: 0; }
html {
background: url('images/yourimage.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
发布于 2009-07-09 12:52:35
使用background-size
属性:http://www.w3.org/TR/css3-background/#the-background-size
发布于 2013-05-07 18:44:28
简而言之,你可以试试这个……
<div data-role="page" style="background:url('backgrnd.png'); background-repeat: no-repeat; background-size: 100% 100%;" >
其中我使用了很少的css和js...
<link rel="stylesheet" href="css/jquery.mobile-1.0.1.min.css" />
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery.mobile-1.0.1.min.js"></script>
它对我来说运行得很好。
https://stackoverflow.com/questions/235855
复制相似问题