473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Overlap relative positioned div's

All,

I have a div in my page that has a set width of 1000px, height of
200px, inside this i declare two more div's, both relatively
positioned and floated left, the first is placed to the top left of
the box and is a 30px square, the other one is set to 970px and is
naturally positioned next to the square and so fills all the way to
the right hand edge of the box.

Now i need the second (wider) box to overlap the square and so start
at the left hand edge of the box - this has been achieved by setting
the left property of the wider box to -30 but obviously this leads to
a gap on the right hand side of 30 pixels, however when i increase the
width of the wider box by the extra 30 pixels required to put it's
right edge all the way to the edge of the containing div (or if i even
make it one pixel wider - 971px) it automatically pushes the box down
to the next line because of the relative positioning.

It seems that the CSS is not taking into account the fact that the box
has been pushed 30 pixels to the left when calculating if there is
enough space to fit the box on the same line as the square.

Has anybody come across anything like this before - is there a
different approach that can be taken to solve the problem without
using the float property? I would like to try to avoid the use of
absolute positioning if possible.

Cheers

Ian

May 11 '07 #1
7 9284
rf
"Cruelemort" <ia********@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
All,

I have a div in my page
url?
May 11 '07 #2
On May 11, 12:19 pm, "rf" <r...@invalid.comwrote:
"Cruelemort" <ian.ing...@gmail.comwrote in message

news:11**********************@p77g2000hsh.googlegr oups.com...
All,
I have a div in my page

url?
Can't give a link to the actual app because it is not on an external
web server, however i have just built an example application which
demonstrates the problem -

http://thepartyhouse.co.uk/sandbox/css/index.html

Strangely this example works fine in Firefox (my actual app does not)
but IE still shows the problem, the style sheet (http://
thepartyhouse.co.uk/sandbox/css/stylesheet.css) shows the containing
div is 800px wide and the other_div is 780px wide, the other div is
shifted 30px left to enable overlap with the square div so it should
start at the left edge of the containing div and go to 20 pixels short
of the right edge, but instead it is dropped to the row below.

Ian

May 11 '07 #3
Cruelemort wrote:
All,

I have a div in my page that has a set width of 1000px, height of
200px, inside this i declare two more div's, both relatively
positioned and floated left, the first is placed to the top left of
the box and is a 30px square, the other one is set to 970px and is
naturally positioned next to the square and so fills all the way to
the right hand edge of the box.

Now i need the second (wider) box to overlap the square and so start
at the left hand edge of the box - this has been achieved by setting
the left property of the wider box to -30 but obviously this leads to
a gap on the right hand side of 30 pixels, however when i increase the
width of the wider box by the extra 30 pixels required to put it's
right edge all the way to the edge of the containing div (or if i even
make it one pixel wider - 971px) it automatically pushes the box down
to the next line because of the relative positioning.

If you are "floating" then it is not "left" but "margin-left" property
that you want to set. Also you did not indicate whether or not you have
margins, borders and padding value that also are added to the overall
width...
>
It seems that the CSS is not taking into account the fact that the box
has been pushed 30 pixels to the left when calculating if there is
enough space to fit the box on the same line as the square.

Has anybody come across anything like this before - is there a
different approach that can be taken to solve the problem without
using the float property? I would like to try to avoid the use of
absolute positioning if possible.
It does seem that absolute positioning is really what you are trying to
do. BTW it is going to "really look good" to folks with 800x600 displays...
--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
May 11 '07 #4
On May 11, 2:32 pm, "Jonathan N. Little" <lws4...@centralva.net>
wrote:
Cruelemort wrote:
All,
I have a div in my page that has a set width of 1000px, height of
200px, inside this i declare two more div's, both relatively
positioned and floated left, the first is placed to the top left of
the box and is a 30px square, the other one is set to 970px and is
naturally positioned next to the square and so fills all the way to
the right hand edge of the box.
Now i need the second (wider) box to overlap the square and so start
at the left hand edge of the box - this has been achieved by setting
the left property of the wider box to -30 but obviously this leads to
a gap on the right hand side of 30 pixels, however when i increase the
width of the wider box by the extra 30 pixels required to put it's
right edge all the way to the edge of the containing div (or if i even
make it one pixel wider - 971px) it automatically pushes the box down
to the next line because of the relative positioning.

If you are "floating" then it is not "left" but "margin-left" property
that you want to set. Also you did not indicate whether or not you have
margins, borders and padding value that also are added to the overall
width...
It seems that the CSS is not taking into account the fact that the box
has been pushed 30 pixels to the left when calculating if there is
enough space to fit the box on the same line as the square.
Has anybody come across anything like this before - is there a
different approach that can be taken to solve the problem without
using the float property? I would like to try to avoid the use of
absolute positioning if possible.

It does seem that absolute positioning is really what you are trying to
do. BTW it is going to "really look good" to folks with 800x600 displays...

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIOhttp://www.LittleWorksStudio.com
Ok looking at margin-left and absolute positioning.

It is a throw-away prototype so does not matter how good it looks to
800x600 displays, so long as it is done very quickly.

Thanks for your help.

Ian

May 11 '07 #5
Cruelemort wrote:
I have a div in my page that has a set width of 1000px,
Consider yourself duly chastized.
height of
200px, inside this i declare two more div's, both relatively
positioned and floated left,
Both? What does that do?
the first is placed to the top left of
the box and is a 30px square, the other one is set to 970px and is
naturally positioned next to the square and so fills all the way to
the right hand edge of the box.
[trimmed]
>
Has anybody come across anything like this before - is there a
different approach that can be taken to solve the problem without
using the float property? I would like to try to avoid the use of
absolute positioning if possible.
You haven't really explained -- this may surprise you -- what your real
problem is. You've just presented a mash of conflicting restrictions and
asked us to solve the conflict. One of the advantages of a real URL is
that we get to see what you're trying to do and (with some guessing)
why. Your floating and positioning are probably not your real goals,
just your attempts to get there. Right?

Is it true you want a square box to appear in front of a wider
rectangle, both of them starting at the exact same upper-left corner?
And that this corner is also the upper-left corner of the bigger
containing div (set in your example to 1000px)?

One (apparent) solution: Change the markup to have nested divs. Might
not make sense for your content, but we can't know that. Using your
example at http://thepartyhouse.co.uk/sandbox/css/index.html, try

<div id="containing_div" class="containing_div">
<div id="other_div" class="other_div">
<div id="square_div" class="square_div"></div>
</div>
</div>

with float and z-index and positon:relative and left:-30px removed from
the CSS:

div.containing_div
{ position: absolute;
left: 50px;
width: 800px;
height: 200px;
border: 1px solid black; }

div.square_div
{ width: 30px;
height: 30px;
top: 0px;
left: 0px;
background-color: red; }

div.other_div
{ width: 780px;
height: 50px;
top: 0px;
background-color: blue; }

In your other post you mentioned differences between IE and FF. I'm not
sure what _that_ was, but in general, you will have much better results
if you put the browsers into standards mode, as opposed to quirkss mode.
Add <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"to the start of your
HTML. Also add a <titleelement and a character encoding, then check
for validation errors. Don't forget to include borders, margins, and
padding when you're doing something crazy like attempting pixel-perfect
block fitting.

--
John
May 11 '07 #6
On 2007-05-11, Jonathan N. Little <lw*****@centralva.netwrote:
Cruelemort wrote:
>All,

I have a div in my page that has a set width of 1000px, height of
200px, inside this i declare two more div's, both relatively
positioned and floated left, the first is placed to the top left of
the box and is a 30px square, the other one is set to 970px and is
naturally positioned next to the square and so fills all the way to
the right hand edge of the box.
[...]
If you are "floating" then it is not "left" but "margin-left" property
that you want to set.
left will work since it's a relatively positioned float.
May 11 '07 #7
On 2007-05-11, Cruelemort <ia********@gmail.comwrote:
All,

I have a div in my page that has a set width of 1000px, height of
200px, inside this i declare two more div's, both relatively
positioned and floated left, the first is placed to the top left of
the box and is a 30px square, the other one is set to 970px and is
naturally positioned next to the square and so fills all the way to
the right hand edge of the box.

Now i need the second (wider) box to overlap the square and so start
at the left hand edge of the box - this has been achieved by setting
the left property of the wider box to -30 but obviously this leads to
a gap on the right hand side of 30 pixels, however when i increase the
width of the wider box by the extra 30 pixels required to put it's
right edge all the way to the edge of the containing div (or if i even
make it one pixel wider - 971px) it automatically pushes the box down
to the next line because of the relative positioning.

It seems that the CSS is not taking into account the fact that the box
has been pushed 30 pixels to the left when calculating if there is
enough space to fit the box on the same line as the square.
Yes, that's exactly what it's doing. For relative positioning,
everything is laid out as if it weren't relatively positioned first,
then, at the last minute, translated by the relative offset you set with
top, left, etc.
Has anybody come across anything like this before - is there a
different approach that can be taken to solve the problem without
using the float property? I would like to try to avoid the use of
absolute positioning if possible.
Why? Absolute positioning is the obvious way to do this.

I don't know what's in the second div. If it doesn't contain any inline
content, just leave it as normal flow display: block (the default). It
will get stacked behind the left float, but you can bring it in front of
it with "position: relative; z-index: 1"
May 11 '07 #8

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

Similar topics

0
by: Mike Kozlowski | last post by:
I have an absolutely positioned block on the top of my page, a block floated left, and a third block in the normal flow. IE6 and Mozilla 1.4 disagree on where the floated block should be placed --...
0
by: louissan | last post by:
Hi all, I have a slight display speed problem under IE5/6 when putting an onmouseover/out effect in a <div> tag inserted inside a relatively positioned parent block. Mozilla and Safari handle...
4
by: louissan | last post by:
Hi all, I've met a problem with Opera and its ability to render absolutely positioned divs inside relatively positioned parent blocks, themselves contained inside a relatively positioned...
8
by: Asad | last post by:
Hi, I am basically trying to accomplish drop down menus for navigation on a site. And I'm pretty much done except I am having one problem. The z-index is not working with relative positioning! ...
6
by: Gérard Talbot | last post by:
Hello fellow stylers, When trying this page http://www.gtalbot.org/BrowserBugsSection/PercentualRelativePositioning.html I get different rendered layouts with IE 6, IE 7 beta 2, Firefox...
6
by: Seth Illgard | last post by:
Hi, Im writting a custom CMS and everything looks great, except when I see the results in IE. What im trying to do is: *Have an image in a layer (or relative positioned, or just margined). The...
3
by: Justin England | last post by:
Background: I am working for a client putting a textbook online. The layout of the textbook is straight forward and is easy enough to style with <h?>, <p>, <uland <oltags. The text book also...
10
by: Mark | last post by:
According to my book on CSS, if you apply 'position: relative' to a block-level element, it will stay exactly where it is. However, you can then use top, left etc. to offset the element relative to...
5
by: liketofindoutwhy | last post by:
It seems like there are only 4 methods to overlap 2 images using CSS? There are two images, each with its own URL. Using CSS, there seems to be 2 ways to overlap them (the task is actually to put...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.