Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Dynamic width of absolute positioned element

Reply
Thread Tools

Dynamic width of absolute positioned element

 
 
mike eli
Guest
Posts: n/a
 
      09-01-2004
Hi,

I have several absolute positioned elements inside an absolute
positioned DIV.
I would like one of the nested elements to have a dynamic width. I set
it's left and right attributes to 5, so the the element should have a
width = parentWidth - 10; This is the desired behaviour, but it won't
work. I still have to specify a width or the element has a width of 0.
Setting the width to '100%' doesn't give me the desired effect; it
takes the width of the parent element. Can anybody help me? thanks.

ex.

<div style="position:absolute; left:20px; top:20px; width:200px;
height:200px; border:solid black 1px">
<div style="position:absolute; left:5px; top:0px; right:5px;
background-color:blue"></div>
</div>
 
Reply With Quote
 
 
 
 
noone
Guest
Posts: n/a
 
      09-02-2004

"mike eli" <> skrev i en meddelelse
news: om...
> Hi,
>
> I have several absolute positioned elements inside an absolute
> positioned DIV.
> I would like one of the nested elements to have a dynamic width. I set
> it's left and right attributes to 5, so the the element should have a
> width = parentWidth - 10; This is the desired behaviour, but it won't
> work. I still have to specify a width or the element has a width of 0.
> Setting the width to '100%' doesn't give me the desired effect; it
> takes the width of the parent element. Can anybody help me? thanks.
>
> ex.
>
> <div style="position:absolute; left:20px; top:20px; width:200px;
> height:200px; border:solid black 1px">
> <div style="position:absolute; left:5px; top:0px; right:5px;
> background-color:blue"></div>
> </div>


Hi Mike

Absolute positioning means absolute and not relative.
If you position som element with absolute positioning, the element
absolutely doesn't care about its parents position.
You need relative to do that.
And if your "left" is 5 and your "right" is 5, then of course your width
becomes 0, because you are setting the margins of the element.
So both your lft and right margins are 5, not much space in between there.
Go to www.w3schools.com and learn some more about html

happy coding
Robert


 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      09-02-2004
On Thu, 2 Sep 2004 10:25:14 +0200, noone <1@2.3> wrote:

[snip]

> Absolute positioning means absolute and not relative.
> If you position som element with absolute positioning, the element
> absolutely doesn't care about its parents position.


Actually, if you read the specification a little more closely, you'll see
that that isn't true.

An absolutely positioned block is "explicitly offset with respect to its
containing block" (9.6 - Absolute positioning). A relatively positioned
block is "laid out according to the normal flow" and "may be shifted
relative to this position" (9.4.3 - Relative positioning").

If you add content to the inner DIV in the OP's example, you'll see that
Opera and Mozilla display the elements as intended. IE, being crap as
usual, doesn't and I doubt it will without some kind of hack (CSS or
Javascript).

In any case, the first place to take this is to the stylesheet group:

comp.infosystems.www.authoring.stylesheets

If they can't find a solution, then perhaps a script solution is warranted.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
DU
Guest
Posts: n/a
 
      09-02-2004
mike eli wrote:

> Hi,
>
> I have several absolute positioned elements inside an absolute
> positioned DIV.
> I would like one of the nested elements to have a dynamic width. I set
> it's left and right attributes to 5, so the the element should have a
> width = parentWidth - 10; This is the desired behaviour, but it won't
> work. I still have to specify a width or the element has a width of 0.
> Setting the width to '100%' doesn't give me the desired effect; it
> takes the width of the parent element. Can anybody help me? thanks.
>
> ex.
>
> <div style="position:absolute; left:20px; top:20px; width:200px;
> height:200px; border:solid black 1px">
> <div style="position:absolute; left:5px; top:0px; right:5px;
> background-color:blue"></div>
> </div>


Setting simultaneously left and right absolute values to the inner div
does not make sense.

Better:

<div style="position:absolute; left:20px; top:20px; width:200px;
height:200px; border:solid black 1px">
<div style="position:absolute; left:5px; top:0px; width: 190px;
background-color:blue;"></div>
</div>

or

<div style="position:absolute; left:20px; top:20px; width:200px;
height:200px; border:solid black 1px">
<div style="position:absolute; left:2%; top:0px; width: 96%;
background-color:blue;"></div>
</div>

and here, MSIE 6 must be triggering standards compliant rendering mode
in order to render accordingly.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Netscape 7.2
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I put an element below another element, that's not absolutely positioned? felipevaldez@gmail.com Javascript 5 09-10-2006 01:56 AM
Setting absolutely positioned element top/left in Mozilla Hoss Javascript 0 09-03-2006 11:58 PM
Composite Control - Panel scrollbars for "absolute" positioned child controls Parag Mahajan ASP .Net Building Controls 2 06-03-2006 09:40 AM
Wierd offsetTop value with relative positioned Element in table inWin IE 6 Markus Fischer Javascript 3 09-08-2004 01:35 PM
Getting statically positioned element window offset positions (left, top)? Pieter Van Waeyenberge Javascript 1 02-09-2004 01:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57