2015-06-22 32 views
0

我有一个图片大小:240px/240px。这个尺寸的图片只能在宽屏幕上显示,在手机上这张图片必须是80px/80px。 我曾经尝试过:如何减少背景图片的大小?

.picture{ 
    height:100%; 
    min-height: 240px;   
    background: url("../../img/picture.png") no-repeat; 
    background-size: cover; 
    background-position: 50% 50%; 
} 
@media screen and (max-width: 480px) .picture { 
    height: 80px; 
    transform:scale(.3); 
} 

但是这种规模的父母阻止,BG比例不对,完全正确的,但是这不是我所需要的。这只是作物bg图片。

回答

1

如果你想设置固定的背景图像,这是例如缩放和调整你的背景图片:

.pic-wrap { 
 
    display: block; 
 
    height: 296px; 
 
    background-image: url(https://pbs.twimg.com/profile_images/590966305248784384/1gX6-SY6_400x400.jpg); 
 
    background-size: 256px; 
 
    background-position: 20px 50%; 
 
    background-repeat: no-repeat; 
 
    padding-left: 296px; 
 
    border: 1px solid #ddd; 
 
} 
 

 
@media only screen and (max-width: 320px) { 
 
    .pic-wrap { 
 
    background-size: 96px; 
 
    height: 126px; 
 
    padding-left: 126px; 
 
    } 
 
}
<div class="pic-wrap"> 
 
    <span class="label">Test</span> 
 
</div>

+0

这是我所需要的。所有问题都在背景大小:封面;现在我使用背景大小:100%;在宽屏幕和背景大小上:25%;在移动。它是完美的。感谢提示! – ostinred

+0

太棒了!别客气 :) –

1

你缺少对媒体查询{}括号:

.picture{ 
    height:100%; 
    min-height: 240px;   
    background: url("../../img/picture.png") no-repeat; 
    background-size: cover; 
    background-position: 50% 50%; 
    } 


    @media screen and (max-width: 480px) { /* here */ 
     .picture { 
     height: 80px; 
     transform:scale(.3); 
     } 
    } /* here */ 
+0

没有。括号存在,我写这个代码(不复制)。 – ostinred

+0

@ostinred我没有在你的代码中看到括号,http://jsfiddle.net/Leb5f3a6/ – Muhammet

+0

[这里](http://www.jsfiddle.net/Leb5f3a6)是我有的问题,bg作物时你调整窗口的大小。 – ostinred

1

试试这个 -

.picture{ 
    height:100%; 
    min-height: 240px;   
    background: url("../../img/picture.png") no-repeat; 
    background-size: 100% 100%; 
    background-position: 50% 50%; 
} 

@media screen and (max-width: 480px){ 
    .picture { 
     height: 80px; 
     min-height: none; 
     transform:scale(.3); 
    } 
}