简体   繁体   中英

Resizing Background Images in CSS

I'm new to HTML. Can anyone please tell me how can I resize the background image in CSS?

You can use the CSS background-size property.

http://www.w3schools.com/cssref/css3_pr_background-size.asp

I hope that answers the question.

Keywords syntax

background-size: cover;
background-size: contain;

One-value syntax
the width of the image (height set to 'auto')

background-size: 50%;
background-size: 3em;
background-size: 12px;
background-size: auto;

Two-value syntax
first value: width of the image, second value: height

background-size: 50% auto;
background-size: 3em 25%;
background-size: auto 6px;
background-size: auto auto;

Multiple backgrounds values by background-image
Do not confuse this with background-size: auto auto
background-size: auto, auto;
background-size: 50%, 25%, 25%;
background-size: 6px, auto, contain;

background-size: inherit;

more: https://developer.mozilla.org/en-US/docs/Web/CSS/background-size

img{ width:100%;}

Add this into your css and use !important if necessary. this will work.

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