473,382 Members | 1,726 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,382 software developers and data experts.

Clear issue

Hello,

Consider the following design:

<div id="container">
<div id="A" class="A"></div>
<div id="B" class="B"></div>
</div>

And the CSS classes:
.A {float:left; clear:left}
.B {float:left; clear:right}

This does not work well. So I always do as follow:

<div id="container">
<div id="A" class="A"></div>
<div id="B" class="B"></div>
<div id="clear" class="clear"></div>
</div>

Where:
.A {clear:both}

This always happens when I have divs inside other divs.
Does anyone knows how to solve this?

Thanks,
Miguel

Nov 26 '06 #1
4 2325
..oO(shapper)
>Consider the following design:

<div id="container">
<div id="A" class="A"></div>
<div id="B" class="B"></div>
</div>

And the CSS classes:
.A {float:left; clear:left}
.B {float:left; clear:right}

This does not work well.
What's the problem?

Micha
Nov 26 '06 #2
Well,

If I place content inside them or after it in other divs in some
situations the content get outside of the div.

Try to place a border and u will see that the top border will be closed
to the bottom border.

Something like overlay.

Anyway, the clear div solves it.

I just don't understand why,

Thanks,
Miguel

Michael Fesser wrote:
.oO(shapper)
Consider the following design:

<div id="container">
<div id="A" class="A"></div>
<div id="B" class="B"></div>
</div>

And the CSS classes:
.A {float:left; clear:left}
.B {float:left; clear:right}

This does not work well.

What's the problem?

Micha
Nov 26 '06 #3
shapper wrote:
Hello,

Consider the following design:

<div id="container">
<div id="A" class="A"></div>
<div id="B" class="B"></div>
</div>

And the CSS classes:
.A {float:left; clear:left}
.B {float:left; clear:right}
As I understand it a floated element is taken out of the flow of the
document. This means that if you float all the elements within a
containing div then there is no content at all for the containing div.
This does not work well. So I always do as follow:

<div id="container">
<div id="A" class="A"></div>
<div id="B" class="B"></div>
<div id="clear" class="clear"></div>
</div>

Where:
.A {clear:both}

This always happens when I have divs inside other divs.
Does anyone knows how to solve this?
Well as I understand it if you float everything within a containing div
then you can put an additional empty div at the end which is not
floated and has declaration clear: both; applied to it.

This clear declaration on the empty div element will create content
that fills the entire containing div because the clearing declaration
"sees" the floated elements above and extends the top margin of this
empty div at the end such that it fills the area with the floated
elements. The containing div won't "see" the floated elements but it
will "see" the top margin of the empty div at the end which effectively
surrounds the floated elements.

So...

If we have

#container {border: solid 1px black;}
..A {float: left;}
..B {float: right;}

We won't see any border surrounding para's A and B below

<div id="container">
<p class="A">Stuff</p>
<p class="B">Stuff</p>
</div>

However by including an extra div at the bottom clearing both we will
see the border.

#container {border: solid 1px black;}
..A {float: left;}
..B {float: right;}
..atbottom {clear: both;}

<div id="container">
<p class="A">Stuff</p>
<p class="B">Stuff</p>
<div class="atbottom"></div>
</div>

--
Patrick
Brighton, UK

<http://www.patrickjames.me.uk>

Nov 26 '06 #4
..oO(shapper)
>If I place content inside them or after it in other divs in some
situations the content get outside of the div.

Try to place a border and u will see that the top border will be closed
to the bottom border.

Something like overlay.
Yep, because in this case the outer div is completely empty. The inner
divs are floated, hence taken out of the normal flow.
>Anyway, the clear div solves it.
Setting the outer div to "overflow: hidden" does the same - it expands
the div so it contains the floats.

Micha
Nov 27 '06 #5

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

Similar topics

9
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int...
77
by: Ville Vainio | last post by:
I tried to clear a list today (which I do rather rarely, considering that just doing l = works most of the time) and was shocked, SHOCKED to notice that there is no clear() method. Dicts have it,...
1
by: nettleby | last post by:
The Microsoft site has confused me on this issue: http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06_redirection.mspx?mfr=true Says that: "ASP automatically discards...
19
by: Krishanu Debnath | last post by:
Hello, I have a call to hash_map::clear() function which takes long time. someClass::someFunction() { // typedef hash_map<name_id, uintMp; // Mp p; // assuming proper namespace, hash...
17
by: toton | last post by:
Hi, I am using a vector to reserve certain amount of memory, and reuse it for new set of data, to avoid reallocation of memory. so the call is something like vector<my_datav;///the temporary...
34
by: pamela fluente | last post by:
I would like to hear your *opinion and advice* on best programming practice under .NET. Given that several time we cannot change: MyCollection.Clear into the instantiation of a NEW...
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
4
by: Dinsdale | last post by:
I am writing a small console application that runs fine unless I am re- directing the output to a file (i.e. c:\ app.exe >>output.txt) . I have determined that the issue is caused by the...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.