简体   繁体   中英

Aspect ratio for background-image, when data is image/jpeg;base64

I have a div with background-image set to data:image/jpeg;base64 format:

<div style="background-image: url(data:image/jpeg;base64,/9j/4AAQ...

I would like to show full image respecting aspect ratio, using available space. I would normally use:

width: 90vw;
height: 100vh;
background-size: contain;
background-repeat: no-repeat;
background-position: center;

In this case image is stretched using full div size. Any suggestions?

Update: Div with data: http://jsfiddle.net/witepo/bksmhtwc/

Update 2: expected result: http://1drv.ms/1uTj8Nd Div: http://codepen.io/anon/pen/LEZPjj

try this

background-size: cover;
background-repeat: no-repeat;
background-position: center center;

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