简体   繁体   中英

CSS width and height property from background-image property

I'm not sure if I the title's correct, so feel free to edit it to something more descriptive.

How to, if there's a way to, read the width/height of an background-image image and pass it to width/height property of that element in CSS (without the use of JavaScript)?

So, since I think the question is still confusing, I'll best provide an example:

element {
    background: url(image.png);
    width: auto;
    height: auto;
}

I know the above example doesn't work, but I was wondering if there is something similar to it that might.

Thanks!

PS: I can do it in JS, so posting a JS solution won't be necessary.

There is no way to do this with only CSS.

I'm not sure what else there is to say.

It is impossible - workaraound is to put there img, set overflow to hidden, and put second div in with position relative ( it some setup to fit it all, but it works )

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