2017-07-15 40 views
-2

我有一个问题,我需要把我的网页的身体背景图像,但这是响应和适合任何大小..这我应该只做与CSS或JavaScript也可以给例如请适应图像到任何设备

+0

Google上的首次访问是[Perfect Full Page Background Image](https://css-tricks.com/perfect-full-page-background-image/) – adeneo

+0

您试图分享以显示您的问题的任何代码?你介意背景大小吗? –

+0

听起来像是你想要'@ media'和'background-size'的组合。如果正确完成,你不需要任何JS。 –

回答

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

1

对于HTML:

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

对于CSS:

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

告诉我是怎么回事!