tags:

views:

32

answers:

2

I keep getting weird results under Opera 10.60 trying to absolutely position block element inside inline-block element.

Sample code:

<html><head><style type="text/css">
div.container {
    position: relative;
    display: inline-block;
    padding: 5px 100px;
    border: 1px solid red; 
}
div.block {
    display: block; 
    position: absolute; 
    top: 0px; 
    right: 0px; 
    border: 2px solid brown;
}
</style></head><body>

<div class="container">
  <div class="block">(>O.o)></div>
  Quick brown block <a href="#">jumps</a> over relative div. 
</div>

</body></html>

Opera positions .block relative to the last inline element ( in this example) inside the same parent (.container), instead of positioning it relative to the parent.

Am I missing something, or is it just a bug, and I should find the other way around?

A: 

Change position: relative; to position: absolute;

and it will align itself correctly in the browsers. :)

Dan
It works, yes.But on my website I have notifications which are made with the code similar to the sample, and I can't absolute position them around that easy without breaking markup.Looks like I can use your advice and wrap each absolutely positioned .container with another, normally positioned block. It will double the code lenght, though :-)
smugglerFlynn
+1  A: 

wrap your content in a div or something else, then it works. http://jsbin.com/isuke3/edit

Rito
So for this is the best solution, thanks
smugglerFlynn
your welcome :)
Rito