Forum Moderators: not2easy

Message Too Old, No Replies

Newbie question about margins

         

tirengarfio

9:37 pm on Jan 6, 2010 (gmt 0)

10+ Year Member



Hi,

with this code below I show a portrait and some personal data on the right hand side of the photo.


<div id="member">

<div id="portrait" style="float:left">
<img src="uploads/fotografias_miembros/luis.jpg" alt="">
</div>

<div id="data" style="margin-top: 5px">
Luis
</div>

</div>


When i give a value to the margin-top of the "data", the "portrait" is also "margined-top", i mean: it is like i give also the same margin-top value to the photo.

I only want to "margined-top" the personal data, so what should i do?

Regards

Javi

monie

10:50 am on Jan 10, 2010 (gmt 0)

10+ Year Member



hmm... there's probably a bunch of options.

Do you know what height you'll want "portrait" to be? How is the height of the two div's determined?

You might be able to put the two divs inside a table (rather than using float) with no space between the cells and no border. Then you'd set table height and cell widths to whatever you want, and portrait's style to "height:100%;".

Drag_Racer

3:45 pm on Jan 11, 2010 (gmt 0)

10+ Year Member



change margin-top to padding-top

I'm guessing your seeing a bug in IE?

Fotiman

3:49 pm on Jan 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's not a bug, its called "collapsing margins".

Drag_Racer

7:46 pm on Jan 11, 2010 (gmt 0)

10+ Year Member



Fotiman, I am confused as why this would be considered a collapsing margin when we are dealing with margin-top and two element that are side by side?

Are you thinking about a margin from an element we are assuming is above the 'member' div on the page?

Not trying to be difficult, just confused... :)

Fotiman

8:11 pm on Jan 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



From the CSS Spec. regarding Box model and Collapsing Margins (added emphasis is mine):
In this specification, the expression collapsing margins means that adjoining margins (no non-empty content, padding or border areas or clearance separate them) of two or more boxes (which may be next to one another or nested) combine to form a single margin.

[w3.org...]

In other words, the two elements that are side by side can still have a collapsing top-margin.
Collapsing Margins can be a difficult concept to grasp.

Drag_Racer

8:22 pm on Jan 11, 2010 (gmt 0)

10+ Year Member



I did not know that. Thanks man.

Drag_Racer

8:30 pm on Jan 11, 2010 (gmt 0)

10+ Year Member



now I'm more confused...

the spec you posted states

Vertical margins between a floated box and any other box do not collapse (not even between a float and its in-flow children).

Fotiman

9:04 pm on Jan 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry, I only skimmed over your original post and at first glance it sounded like a collapsing margins issue.

Do you have Firebug for Firefox? If not, I would start by getting that, and using it to inspect each box to see what style rules are being applied to each. That might shed more light on it.