背景图片:如果图片较小,如何填充整个div,反之亦然 [英] Background images: how to fill whole div if image is small and vice versa

查看:572
本文介绍了背景图片:如果图片较小,如何填充整个div,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个问题:


  1. 当我尝试在较小的div中使用背景图片时,div只有部分图像。如何显示图片的完整或特定部分?

  1. When I tried to use a background image in a smaller size div, the div shows only part of image. How can I show the full or a specific part of image?

我有一个较小的图片,我想在较大的div中使用。

I have a smaller image and I want to use in a bigger div. But don't want to use repeat function.

CSS中有没有办法处理图片的不透明度。

Is there any way in CSS to manipulate the opacity of an image?


推荐答案

调整图片大小以适合div大小。

使用CSS3, this:

Resize the image to fit the div size.
With CSS3 you can do this:

/* with CSS 3 */
#yourdiv {  
    background: url('bgimage.jpg') no-repeat;
    background-size: 100%;
}

如何在网页上延伸背景图片

关于opacity

#yourdiv {
    opacity: 0.4;
    filter: alpha(opacity=40); /* For IE8 and earlier */
}

或查看CSS图片不透明度/透明度

这篇关于背景图片:如果图片较小,如何填充整个div,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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