views:

36

answers:

2

Hello,

For some reason my Submit and Cancel buttons are not being wrapped in the form tag like I expect them to be (based on their position with in the form tag in the HTML) when I have their float property set to right and left respectively. The two buttons are positioned just outside & below the form div to the far right & left sides.

Link to the HTML & embedded CSS

alt text

How can I make it so the form div wraps the two buttons so they do not appear outside & below the form div?

Thank you
Adam

+2  A: 

Looks like you need to clear the floats. Give this a try.

<form action="#" method="get">
    <textarea name="Reply Textarea" type="text" rows="2" cols="40" wrap="soft"></textarea>
    <input id="buttons" class="submit" type="submit" value="Submit" />
    <input id="buttons" class="cancel" type="button" value="Cancel">
    <br style="clear: both;" />
</form>
Dustin Laine
Yep, that will do it. The reason the floated elements need to be cleared is because as soon as you float something, it no longer interacts with its parent container (unless it's also floated) or any other non-floated elements further down in the markup. Clearing stops this.
Pat
i just want to make sure i understand why this is happening and/or if this is a CSS bug i am encountering.
J3M 7OR3
No this is not a CSS bug, it is by definition. See Pat comment above.
Dustin Laine
@Pat thanks for the explanation @durilai thanks for answering with example. one thing. how come it works when the 'submit' button has a 'float:right' applied to it but the 'cancel' button has no float applied?
J3M 7OR3
@durilai It works then because the cancel button is still in the normal document flow and therefore interacting with it's non-floated parent (the form). Something that helped me get the hang of it when I was starting was thinking about "rows" of floated elements. If you float all the elements in a row (i.e. you float both buttons) there's nothing left to interact with the form, and it collapses above the buttons because as far as it's concerned, there's no element there (the exception is IE6 which still allows non-floated parents to be affected by floated children because it hates coders).
Pat
@Pat I understand you completely now. Thank you again :)
J3M 7OR3
+2  A: 

Remove .cancels float rule:

.cancel{/* no float */}

*tested on Chrome

digitalFresh
yes this does work. can you explain why this works like this? doesn't logic say that it should work with both the buttons having their floats set? or is it that placing a float:left is already an innate behaviour of a non floated item and it just overkills it to include it?
J3M 7OR3
giving a float:left/right style takes the element out of the "box", making it lose some inherited styles. Removing the `float:left` style puts the element inside the "box" and it also covers the `float:right` element.
digitalFresh