简体   繁体   中英

How to adapt image to button size?

How can I make the background image of my button adapt to the button's size? If my image is 2800x1300 how can I make it adapt to a 1000x540 button? Please help a guy in need !

Really depends on the situation but maybe this will help:

background-size: cover

Or

background-size: contain

See what works best.

Use : background-size:cover;

fiddle

 .button { background: url(http://theimageconference.org/wp-content/uploads/2014/01/images-50x50.png) no-repeat; cursor: pointer; border: none; background-size: cover; width: 50px; height: 50px; } 
 <input type="button" name="button" class="button" /> 

You can use background-size:cover;

It Scales the background image to be as large as possible so that the background area is completely covered by the background image. Some parts of the background image may not be in view within the background positioning area

To see how this exactly works go here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM