开发者

Absolute Positioning Issue

开发者 https://www.devze.com 2023-01-17 06:13 出处:网络
I can\'t find a ti开发者_Go百科tle for this because it\'s a complicated issue. Let\'s say i have this:

I can't find a ti开发者_Go百科tle for this because it's a complicated issue.

Let's say i have this:

<div style="color:red;width:900px;height:250px;">
I Can Control This DIV
</div>

<div style="position:absolute;top:0px;color:green;width:40px;height:40px">
I CANNOT control this DIV
</div>

Is there any way for the first div to reserve it's area and the 0px should be beneath it.

I mean i want the second div to stay beneath the first div like it's inside an iframe BUT i don't want to use iframes or frames at all.

Any way? i don't have a prob if it's Javascript solution.

Thanks


You can enclose second div in position:relative container. This way, top:0px will be counted from that div and not the whole window:

http://jsfiddle.net/z9KbD/

Explanation is in definition of position:absolute: Generates an absolutely positioned element, positioned relative to the first parent element that has a position other than static.


Can you wrap both of them in another div and them control that one?


If you give the second div a clear:both, that should do the trick I think you are looking for. Essentially, it will act as a carriage return for that div.

On a side note, if you were looking to absolutely position an element, you will need a parent element that contains it to be relatively positioned. Chris Coyier goes over it in depth here.

0

精彩评论

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