473,666 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9301
rf
"Cruelemort " <ia********@gma il.comwrote in message
news:11******** **************@ p77g2000hsh.goo glegroups.com.. .
All,

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

news:11******** **************@ p77g2000hsh.goo glegroups.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.c o.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...@centra lva.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.LittleWorks Studio.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="containi ng_div">
<div id="other_div" class="other_di v">
<div id="square_div " class="square_d iv"></div>
</div>
</div>

with float and z-index and positon:relativ e 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*****@centra lva.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********@gma il.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
2348
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 -- IE thinks its top margin should be relative to the containing block (i.e., the body), while Mozilla thinks it should be relative to the bottom of the absolutely positioned block. My instincts, of course, are to assume that Mozilla's correct --...
0
1640
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 this finely, though.
4
8730
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 block. I'm surely missing something, but what? Any help would be kindly appreciated :) Here's a code sample:
8
42515
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! Basically I have a page such as this: http://members.rogers.com/asadkhan2/prob2.jpg
6
6075
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 1.5.0.2 and Opera 9.0 build 8367. Firefox 1.5 and Opera 9 will just ignore the CSS declaration
6
10526
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 exact image's coordinates depends in the window size (Fluid design) *The image should display correctly in front(above) another image (header image)
3
10861
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 contains small images of a key that represent a key point within the text. In the printed book, these keys are positioned to the left of the text (in the margins if you will) and some paragraphs may have more than one key. It is important to the...
10
3268
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 its position. However, looking at other people's stylesheets, I often see 'position: relative' applied to elements but without the use of top, left etc., which makes me think using 'position: relative' has some other effect that my book has...
5
10871
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 a "play button" image with size 50 x 50 on top of the bigger image which is a video thumbnail size 200 x 150). 1) Use <div><img ><img ></divwith the play button as the second image and displayed relatively positioned to overlap the first...
0
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.