2

I have a DIV with the following style

.vplayer-container .logo
{
 position: absolute;
 bottom: 50px;
 right: 10px;
 background: url(../img/logo.png) no-repeat;
 border: 1px solid #000000;
 max-width: 50px;
 max-height: 50px;
}

I want that the DIV size is the same as the background image. Since the bg image change, I want it to be set automatically. I can use JavaScript, but I'd prefer a CSS way for that.

I'm targeting HTML5 browsers that is FireFox, Webkit and Opera.

Thanks

Answer:

With Kyle Sevenoaks hint, you can do it by putting an image element inside the DIV.

<div>
<img src="url">
</div>

Remove the Background property and no other styling is needed.

3 Answers 3

3

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.

1
  • Thanks, That is the answer I was looking for :) Put an image within the DIV and everything should go fine.
    – Omar Abid
    Sep 23, 2010 at 13:37
0

CSS cannot do that for background image.

1
  • I forgot to mention, I'm targeting HTML5 browsers only
    – Omar Abid
    Sep 23, 2010 at 13:33
0

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.

1
  • This is a script, the user can put the values; however, doing it for him will make things a lot easier.
    – Omar Abid
    Sep 23, 2010 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.