使图像适应任何设备

时间:2017-07-15 14:45:26

标签: javascript jquery html css

我有一个问题我需要将背景图片放到我的页面正文但这是响应并适合任何大小..这我只应该用css或javascript,可以举个例子

2 个答案:

答案 0 :(得分:1)

对于HTML:

<body class="background">
    <!-- Content goes here -->
</body>

对于CSS:

.background {
    background-image: url(image.png);
    background-size: cover;
    position: fixed;
}

告诉我它是怎么回事!

答案 1 :(得分:0)

对于CSS

.body {
    background-image: url('myImg.jpeg');
    background-position:center top; // you can change this as you like.
    background-repeat:no-repeat;
    -moz-background-size:cover; 
    background-size:cover;
    height: 100%;
    width:100%;
}

为Firefox浏览器添加-moz-background-size

相关问题