如何在CSS中设置背景图片大小? [英] How do I set the background image size in CSS?

查看:454
本文介绍了如何在CSS中设置背景图片大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有如下的CSS代码:

So I have css code as follows:

.jumbobg {
    background: url('http://znc.mane-frame.com/static/silverleaf.png') fixed no-repeat, url('../img/banner-1008444.jpg') no-repeat, grey;
}

我想知道第一张图像(silverleaf.png)-如何使用像素(对于Silverleaf)或auto为该特定图像设置background-size?我尝试使用background-size标记,但是它将调整上面定义的所有背景的大小.

I was wondering, for the first image (silverleaf.png) - how would I set the background-size for that particular image, using either pixels (for silverleaf) or auto? I tried with background-size tag, but it would resize all the backgrounds defined above.

推荐答案

问题是您在background属性中指定了两个背景(用逗号分隔),因此必须对background-size做同样的操作它们的不同值,当您在background-size中仅指定一个值时,该值将同时应用于两个图像:

The thing is that you have specified two backgrounds in background property (separated with comma), so you have to do the same with background-size to get their distinct values, when you specify only one value in background-size it is applied for both images, to be clear:

background-size: 50px 80px;-这是一个值

background-size: 50px 80px, auto;-这是两个值

像在background中一样使用逗号分隔符,因此例如,它应该可以按需工作:

Use comma separator as you did in background, so for example this should work as you want:

background-size: 50px 80px, auto;

这篇关于如何在CSS中设置背景图片大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆