views:

196

answers:

1

Hi,

I have the following code:

    <HTML>
<head>
<style>div{border:dashed 1px silver}</style>
</head>
<BODY style="background: #fff;">

<div style="position: absolute; background: #0f0; width: 256px; height: 96px; overflow: scroll;">

<DIV style=" display: inline-block;position: relative;top: 64px; left: 32px;">
<DIV style="width: 18px; height: 14px; float: left; background: #f00;"></DIV>
<DIV style="float: left">First</DIV>
<div style="clear: both;"></div></DIV>

<DIV style=" display: inline-block;position: relative;top: 96px; left: 32px;">
<DIV style="width: 18px; height: 14px; float: left; background: #0f0;"></DIV>
<DIV style="float: left">Second</DIV><div style="clear: both;"></div></DIV>

</div>

</BODY>
</HTML>

The second div isn't positioned on the 32 x position unless I remove the display: inline-block property, which I need. Is there a way around this?

Edit: it seems to work if I remove display: inline-block, but then the scrollbars will appear horizontally (as the div takes some invisible space).

+1  A: 

You should use the way position:absolute elements are displayed when inside position:relative.
In addition, to avoid the horizontal scroll bar, use overflow-y.

Working example: http://jsbin.com/uveni3

Kobi
Try running the code, you will see two elements where the second is *not* positioned on x: 32; even-though I put it there like that.
rFactor
Oh, but I did: http://jsbin.com/aqoju . Can you show an image or a similar site to what you're trying to achieve?
Kobi
Yes, but I can't use absolute positioning like that... try the modified version that I have on my post.
rFactor
Try this: http://jsbin.com/uwiva3 . The scroll bar might be a whole other problem...
Kobi
check out **overflow-y** : http://jsbin.com/uveni3
Kobi
Seemed to work great!
rFactor
Great, Thank! I've edited the answer to reflect that.
Kobi