tags:

views:

15

answers:

2

Consider following code:

<p style="margin: 30px 0; padding: 0;">Some text some text some text some text some
text some text some text some text</p>

<p style="margin: 30px 0; padding: 0;">Some text some text some text some text some
text some text some text some text</p>

<input type="button" value="Button" style="margin: 30px 0; padding: 0; float: right;"/>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

30px margin expected between last p and input but there is 60px margin. Apparently margin collapsing not working. How to fix CSS rules of input while keeping the ability of input to produce 30px vertical margin on top?

+1  A: 

Try setting display:block on the input

EDIT: Just throw a wrapper around it then?

http://jsfiddle.net/8mqHZ/13/

meder
Strange thing, in sample code it helps, in production it does not. Trying to isolate the cause...
actual
Aha, isolated, the cause is `float: right` (code updated). How to keep it floating right and have no double margin?
actual
@actual Well, margin collapse, if I remember correctly, doesn't apply for floated elements. It might be better to simply set the 30px on one side.
Yi Jiang
@Yi Jiang: the problem is that element on top of the button may have bottom margin of 0 and I can not control this.
actual
A: 

The only solution I have found:

<div style="text-align: right; margin: 30px 0;">
    <input type="button" value="Button" />
</div>​​​​​​​​​​

A little bit of hack.

actual