Size the DIV to the size of the background image

China☆狼群 提交于 2019-11-28 01:38:47
Kyle

CSS can't do this, the div gets its dimensions from the content within it. The background image is purely a mark of styling.

You should be able to do this with Javascript, finding the height and width values and injecting them into an inline style should do it :)

You can also use an <img> tag within the .logo div. This would produce what you intend.

CSS cannot do that for background image.

This is impossible with pure CSS. I think you need to do it with JavaScript. Do you really need this to be dynamic? I think it is less work to change two values in the stylesheet if the logo changes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!