472,782 Members | 1,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

Dynamic width of absolute positioned element

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>
Jul 23 '05 #1
4 4337

"mike eli" <mi************@hotmail.com> skrev i en meddelelse
news:59**************************@posting.google.c 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
Jul 23 '05 #2
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.
Jul 23 '05 #3
DU
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 :)
Jul 23 '05 #4
DU wrote:
mike eli wrote:
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. [...]
<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.


It makes perfect sense and works in working UAs like Gecko-based ones.
Read the specs before posting rubbish.
Better:
[...]
and here, MSIE 6 must be triggering standards compliant rendering mode
in order to render accordingly.


MSIE is junk. It does support neither the "right" nor the "bottom" CSS
property, and it does not have a standards compliant rendering mode. It
may have a mode that is called so, but that's it.

Besides, your From header does not contain an e-mail address which is a
violation of Internet/Usenet standards as well as disregarding of the
Netiquette and most certainly the Acceptable Use Policy of your service
provider. Consider yourself killfiled and most certainly a formal
complaint sent to your SP in case of recurrence.

PointedEars
--
Ever heard of error 18??... it's 18 inches from your screen.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ken Kast | last post by:
Here's my situation. I have a statically positioned table that has an image in a cell. I also have some layers, defined by absolute-positioned DIVs for some animation. Everything works until I...
2
by: Tristan Miller | last post by:
Greetings. I have a two-column web layout, where the first column is just the regular body text with a "marign-right" of 16em, and the second column is an "absolute"-positioned div with a width...
14
by: Harlan Messinger | last post by:
What am I not understanding about the definition of { position: absolute; }? "The box's position (and possibly size) is specified with the 'left', 'right', 'top', and 'bottom' properties. These...
2
by: Rob R. Ainscough | last post by:
I'm slowly (very slowly) working my way thru the bizarre and sadistic world of control positioning in MultiViews (ASP 2.0). I came across this to help me explain (or attempt to anyway) why my web...
2
by: boclair | last post by:
I have just been reading the thread "reason behind containing block rule" It reminded me of a question I have had unresolved for some time What are the rules on the default width of an element...
6
by: Hacking Bear | last post by:
Hi, I still don't quite fully understand how to handle mixing border/margin pixel width with percentage width. In the example below, I want to place side-by-side two DIV boxes inside a box....
2
by: mark4asp | last post by:
What is the best way to write a page that uses min-width and max-width and will work IE6, IE7 and other modern browsers? I realise that I need a hack for IE6 but not for IE7 so what is the...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
7
by: chemlight | last post by:
I am having an issue with HTML elements not printing when positioned absolutely when they extend beyond the first page. I am working on some foreign tax refund forms. The forms are cut into multiple...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.