473,761 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Container of floated elements and layout

Hello.

The issue is quite known: you have a block-level container holding a
set of floated elements and you need that the container's content
height take the floated elements' dimensions into consideration. E.g.:

<div class="images">
<div class="image">< img src="example1.p ng" width="160" height="120"
alt=""></div>
<div class="image">< img src="example2.p ng" width="160" height="120"
alt=""></div>
</div>
<p>The contents resume here blah, blah, blah...</p>

CSS definitions:

div.images { margin-bottom: 1em; }
div.image { float: left; width: 160px; margin-right: 2em; }

Because all the elements in the container are floated, their height
will not affect the container's. This will cause the following <p> to
be not laid out as intended, i.e., below the container.

The traditional solution involves the addition of extra markup at the
end of the container, which uses the /clear/ CSS property to suggest
that the respective element be pushed down, past the floats (e.g. <div
style="clear:bo th"></div>). This expands the container's height,
producing the desired result. Although it seems to work, such solution
is at least disturbing, IMHO.

I think there should be a (CSS) way for authors to suggest that
intended behavior without the need of adding extra markup and without
knowledge of the element that follows the container. In other words,
it should be possible to specify, at the container level, that its
contents should affect its calculated dimensions, regardless of their
nature.

Does anybody else share the same, or a similar point of view? Is there
anything else I should know about this matter? Is there a better or
more logical solution, given the CSS implementations at hand?

Thank you,

--
Ney André de Mello Zunino
Jul 20 '05 #1
2 2874
Ney André de Mello Zunino wrote:

The issue is quite known: you have a block-level container holding a
set of floated elements and you need that the container's content
height take the floated elements' dimensions into consideration. E.g.:

<div class="images">
<div class="image">< img src="example1.p ng" width="160" height="120"
alt=""></div>
<div class="image">< img src="example2.p ng" width="160" height="120"
alt=""></div>
</div>
<p>The contents resume here blah, blah, blah...</p>

CSS definitions:

div.images { margin-bottom: 1em; }
div.image { float: left; width: 160px; margin-right: 2em; }

Because all the elements in the container are floated, their height
will not affect the container's. This will cause the following <p> to
be not laid out as intended, i.e., below the container.

I think there should be a (CSS) way for authors to suggest that
intended behavior without the need of adding extra markup and without
knowledge of the element that follows the container. In other words,
it should be possible to specify, at the container level, that its
contents should affect its calculated dimensions, regardless of their
nature.
The CSS sibling selector would do what you want.

..container + * { clear: both }

but sibling selectors are not recognized by MSIE/Win, possibly others
as well.
Does anybody else share the same, or a similar point of view? Is there
anything else I should know about this matter?
Floats are much trickier than some people believe. They can lead to
all sorts of problems.
Is there a better or
more logical solution, given the CSS implementations at hand?


You could assign an id to the last item, and explicitly not float it,
but that still involves changing the html. Moreover, I tried that
once and vaguely recall other problems as a result of the trick.

--
Brian
follow the directions in my address to email me

Jul 20 '05 #2
Jim Dabell wrote:
I think there should be a (CSS) way for authors to suggest that
intended behavior without the need of adding extra markup and without
knowledge of the element that follows the container. In other words,
it should be possible to specify, at the container level, that its
contents should affect its calculated dimensions, regardless of their
nature.


The CSS sibling selector would do what you want.


No, it wouldn't. It doesn't affect the dimensions of the parent element, it
just makes sure the following element is in the right place. This is
useless in the (extremely) common situation where there is a
border/background that should be applied to the containing element.


I see your point, but I think the op was asking about proper placement
of an element after the floated element. He seemed to be talking
about the difficulty of getting a margin between a box whose height is
0 because its contents are floated, and an element after that box.

--
Brian
follow the directions in my address to email me

Jul 20 '05 #3

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

Similar topics

26
3771
by: puzzled | last post by:
Okay, so my subject sounds a bit crass. As much as I'd like to totally embrace css and avoid "deprecated" usage, sometimes the deprecated stuff is so much easier and more effective. Plus, it at least does what I want it to, while I'm left puzzled trying to make a css implementation do the same thing. Here is a simple example. I want to have four identical-sized images displayed in a two-by-two arrangement, wtih room for a centered...
3
2859
by: Lee K. Seitz | last post by:
I'm redesigning this page for more up-to-date browser standards: <http://home.hiwaay.net/~lkseitz/hhs/winners.shtml>. Note the use of an "invisible" table to position the "visible" ones. I'm attempting to get a similar layout using CSS. So far the best I've come up with is <http://home.hiwaay.net/~lkseitz/hhs2/winners.shtml>. (CSS at <http://home.hiwaay.net/~lkseitz/hhs2/hhs.css>.) The problems (all Windows): 1. In IE 6 and NN 7,...
24
2890
by: Thomas Mlynarczyk | last post by:
Hi, Here's what I have: <div> <img ...><br> Caption text </div> The div is floated left and has no width set, the content is centered, there are no margins or padding on the <img> (just a bottom margin and
1
4052
by: Marek Mänd | last post by:
I have question regarding (clearing) floats and margin-top on DL and HR elements. http://www.hot.ee/idaliiga/testcases/dl/language-chosing-selector.htm Namely the IE6 doesnt calculate the margin-top on the DL (definition list) element correctly. It starts to add topmargin at current fontsizes and layout when i tell him to have 38px topmargin. Can this be fixed somehow to normal?
4
2902
by: sweep | last post by:
Hi there, I have a problem with some CSS I'm writing and I was looking for a little help. I have a nav bar at the top and left side of my page in CSS which work fine. The remaining space has a div which I'm using for body text. Floated to the right of this are two image boxes and a broken out quotation from the page (this box is wider than the images). The layout is working, except that the text in the main section doesn't seem to wrap...
4
2482
by: Gustaf | last post by:
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>
9
2611
by: Daniel Kabs | last post by:
Hello there again! On my quest to remove layout tables in favor of CSS controlled elements, I am faced with quite a problem. A table cell that has no explicit width attribute set usually adapts its width to accommodate the content nicely. This is not the case when the content contains floats. I guess floats do not contribute to the table cell width as floated elements are taken out
3
3232
by: David Golightly | last post by:
I'm taking a stab at making CSS sparklines - see http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR&topic_id=1&topic= <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > <head> <title>Sparklines</title> <style type="text/css">
3
3208
by: =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= | last post by:
Hello. I seek confirmation for the reasons behind a margin-related behavior I have observed. I have set up a simple test page to illustrate the issue. The page shows a very simple 2-column layout, where columns are contained in /div/ elements. The first column is floated left and the second one is offset by a left margin. You should be able to notice that the contents of the first column are lower than those of the second one. Is...
0
9554
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
9377
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
9989
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
9811
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
6640
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
5266
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
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
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.