如何拉伸背景图片来填充div [英] How to stretch the background image to fill a div

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

问题描述


  1. 图像的大小是固定的(60px) 。

  2. 改变div的大小

如何拉伸背景图以填充整个背景的div?

#div2 {
background-image:url(http:// s7。 static.hootsuite.com/3-0-48/images/themes/classic/streams/message-gradient.png);
height:180px;
width:200px;
border:1px纯红色;
}

检查这里的代码

解决方案

b

  background-size:100%; 

添加到背景图片下的css中。



<您也可以指定确切的尺寸,即:

  background-size:30px 40px; 

这里: JSFiddle


I want to set a background image to different divs, but my problems are:

  1. The size of image is fixed(60px).
  2. Varying div's size

How can I stretch the background-image to fill the whole background of the div?

#div2{
  background-image:url(http://s7.static.hootsuite.com/3-0-48/images/themes/classic/streams/message-gradient.png);
  height:180px;
  width:200px;
  border: 1px solid red;
}

Check the code here.

解决方案

Add

background-size:100%;

to your css underneath background-image.

You can also specify exact dimensions, i.e.:

background-size: 30px 40px;

Here: JSFiddle

这篇关于如何拉伸背景图片来填充div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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