2

Submit buttons don't seem to clear properly without also adding float. Can someone clear this up for me (no pun intended).

http://jsfiddle.net/qb5TH/

CSS:

.left {float:left}
.clear {clear:both}

Form:

<form>
  <label class="left">Label</label>
  <input type="text" class="left">
  <label class="clear left">Label</label>
  <input type="text" class="left">
  <input type="submit" class="clear">
</form>
braX
  • 11,506
  • 5
  • 20
  • 33

2 Answers2

1

I might not be exactly clear on your intent but if you want to get your button to it's own line you can force it to use display: block and it will go to the next line.

Here's the CSS:

.left {float:left;}
.clear {clear:both;}
input[type=submit] {display: block;}

**jsfiddle sample here

sisdog
  • 2,649
  • 2
  • 29
  • 49
1

The reason why the submit button doesn't move to the next line is because input is an inline element. According to the CSS spec, clear is ignored on inline elements (relevant quote: "Applies to: block-level elements"). Setting float on the submit button works because setting float in most cases also sets display: block. You can achieve the same effect by directly setting display: block on the submit buttons that you want to clear:

.left {float:left}
.clear {clear:both}
input[type=submit].clear {display:block}
Community
  • 1
  • 1
Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40