Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Can I resize the background image by changing the width and height?

Tags:

css

Given the following CSS rule,

#block1 {
 text-indent: -1000em;
 background: transparent url(../images/xxx.png) no-repeat scroll center center;
 width: 100px;
 height: 50px;
 display: inline-block;
}

Assume the image xxx.png is of dimension 100px by 50px. If I need to make this image displayed on #block1 looks smaller, can I simply change the width and height of #block1 or I have to first re-size the image and then change the width and height of the #block1 accordingly.

thank you

like image 221
q0987 Avatar asked Nov 19 '25 21:11

q0987


2 Answers

You can't in CSS1 and 2, but CSS3 supports the background-size property, which if you set to 100% should give you what you are looking for.

However, you probably should just resize the background image though, unless you have a compelling reason not to :)

like image 189
Henry C Avatar answered Nov 22 '25 13:11

Henry C


CSS can only position the image, not adjust it. If you absolutely needed to resize the image through CSS, you'd have to have the image actually inserted as an img tag, then position it behind the content. It's best just to edit it.

like image 22
Elle H Avatar answered Nov 22 '25 11:11

Elle H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!