111

I have the following code:

<div style="float: left; width: 100%;">
  <label style="float: left;">ABC</label>  
  <input style="float: left; font-size: 0.5em;" type="button"   onclick="addTiny(0,'Question_Text'); return false;" value="&#x25BC;" title="Editor" />   
  <input style="float: left; font-size: 0.5em;" type="button" onclick="remTiny(0,'Question_Text'); return false;" value="&#x25B2;" title="Hide" />   

  <div class="adm">
    <textarea rows="2;" style="width: 100%" class="text-box multi-line mceEditor">
      abc
    </textarea>
  </div>
</div>

My problem is that the div with class adm floats to the left and so goes on the same line as the label and two input buttons. Is there a way that I can make this shift away from floating?

mskfisher
  • 3,177
  • 3
  • 33
  • 47
TonyG
  • 1,585
  • 2
  • 13
  • 17

10 Answers10

121

A standard approach is to add a clearing div between the two floating block level elements:

<div style="clear:both;"></div>
Shad
  • 14,384
  • 2
  • 20
  • 34
72

Sometimes clear will not work. Use float: none as an override

Matthew Lock
  • 12,582
  • 11
  • 88
  • 124
DanKodi
  • 3,342
  • 26
  • 26
32

You could modify .adm and add

.adm{
 clear:both;
}

That should make it move to a new line

Brett
  • 4,001
  • 2
  • 24
  • 38
10

add style="clear:both;" to the "adm" div.

tjm
  • 7,342
  • 2
  • 29
  • 48
4

Okay I just realized the answer is to remove the first float left from the first DIV. Don't know why I didn't see that before.

TonyG
  • 1,585
  • 2
  • 13
  • 17
3

You should also check out the "clear" property in css in case removing a float isn't an option

Trey
  • 5,443
  • 4
  • 22
  • 29
3

The css clear: left in your adm class should stop the div floating with the elements above it.

Chris Kent
  • 852
  • 10
  • 18
1

For some reason none of the above fixes worked for me (I had the same problem), but this did:

Try putting all of the floated elements in a div element: <div class="row">...</div>.

Then add this CCS: .row::after {content: ""; clear: both; display: table;}

ezgor
  • 11
  • 1
0

Just add overflow:hidden in the first div style. That should be enough.

StardustGogeta
  • 3,216
  • 2
  • 17
  • 32
sunny
  • 1
-1

There's a class in bootstrap for it

class="clearfix";

TS71M
  • 3
  • 1
  • 3