473,888 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Container <div> won't contain

I'm sure I've got this working before, but I always forget how to do it,
because CSS isn't intuitive in this case. I got a simple 2 column layout:

<div id="container" >
<div id="left">

</div>
<div id="right">

</div>
</div>

The #container div *contains* #left and #right, thanks to the
encapsulation principle of XML. However, when I add borders or
backgrounds to the divs, it's evident that only IE gets this
relationship. The otherwise standard-conformant browsers are squeezing
in an empty #container div at the top, *before* the other two. Why is
this, and what's the workaround/sanctioned way to do it?

There's an example here for anyone to play with:

http://gusgus.cn/temp/index.html
http://gusgus.cn/temp/titlepage.css

Gustaf
Jun 27 '06 #1
4 2491
Gustaf wrote:
The #container div *contains* #left and #right, thanks to the
encapsulation principle of XML. However, when I add borders or
backgrounds to the divs, it's evident that only IE gets this
relationship. The otherwise standard-conformant browsers are squeezing
in an empty #container div at the top, *before* the other two. Why is
this, and what's the workaround/sanctioned way to do it?


Bug in IE. Floating elements takes them out of normal flow.

http://www.complexspiral.com/publica...aining-floats/

Jun 27 '06 #2

Gustaf wrote:
I'm sure I've got this working before, but I always forget how to do it,
because CSS isn't intuitive in this case. I got a simple 2 column layout:
http://brainjar.com/css/positioning/
The otherwise standard-conformant browsers are squeezing
in an empty #container div at the top, *before* the other two.


They all (including IE) place the outer <div>, as it ought to be,
outside and around the inner <div>s, not "before" the inner <div>s.
However owing to IE's flakey handling of float it gets the vertical
extent of the outer <div> wrong (too big). Correct behaviour is to
treat it as empty and collapse it to a mere horizontal line, which
naturally then appears to be "before" its children.

Floated elements can extend downwards out of their parent container.
This is correct and necessary behaviour, as described here:
http://brainjar.com/css/positioning/default3.asp
This is so that floats can be of large vertical extent, floating
alongside many other elements. IE is broken.

If you want a real browser to work as IE does anyway, then place an
element after the floated <div>s but within their container, don't
float it and do use clear on it. This forces the outer container to
stretch downwards and wrap entirely around its children. This
additional clear is safe with IE.

Jun 27 '06 #3
Andy Dingley <di*****@codesm iths.com> wrote:
If you want a real browser to work as IE does anyway, then place an
element after the floated <div>s but within their container, don't
float it and do use clear on it.


Thanks both of you. Great articles and explanation!

Gustaf
Jun 27 '06 #4
Andy Dingley <di*****@codesm iths.com> wrote:
If you want a real browser to work as IE does anyway, then place an
element after the floated <div>s but within their container, don't
float it and do use clear on it.


And watch all your text disappear in IE
http://www.positioniseverything.net/.../peekaboo.html

--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
actual facts is optional."
Jun 27 '06 #5

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

Similar topics

7
2164
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
23
4108
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to <foo/>) From XHTML specification:
61
24542
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will 'stretch'</td> <td valign="top" width="300">some data that won't 'stetch'</td> </tr> </table>
3
5016
by: Philip | last post by:
I am trying to make a bunched of left-floated divs that will be contained in a larger div. the floated divs all contain a left-floated img and text of varying sizes. If I don't set a height (or height:auto) the larger div doesn't seem to see the nested divs, and they spill out the bottom. IE seems to automatically resize the larger div as long as I set the height to 100% or any pixel size. Mozilla doesn't recognize the percent, and...
15
2271
by: scott | last post by:
Hello, I'm working on updating some of my table-based sites to use CSS instead of tables. One of my sites has a header that is composed of three elements: A B C In my prior design, this was done using a table. A, B, and C were each <tdelements.
7
3645
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it simple and schematic, to see if there is a simple Ajax answer to this. A. I have an HTML page which has some pure html/css code representing a GRID of cell. The page may also contain other objects (images, etc). B. On the server I have a windows...
28
5392
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the </p>s included as well. <P>aaaaaaaaa</p><DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</p></DIV>
10
3213
by: Summercoolness | last post by:
so i am starting to use more of <br /and <div style="clear: both" / which is the XHTML style... now, won't those actually confuse the old browsers? for example, will the old browser treat the "div" as not closing, and so everything after the div will be treated as part of that div?
5
5271
nathj
by: nathj | last post by:
Hi All, I'm working on a new site that has a two column layout underneath a title bar. If you check out: http://www.christianleadership.org.uk/scratch/mainpage.php using IE or Opera you will see what I am after as these browsers work fine. However, in FF the results are slightly different - take a look and you'll see that the <p>, within <div class="mainContent"> has shot way over to the right. I've been working on this for 2days now...
0
9961
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
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...
1
10886
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
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
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5824
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...
1
4642
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
3
3252
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.