开发者

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!

P.S: 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 )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜