117

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,291
  • 4
  • 35
  • 48
TonyG
  • 1,645
  • 2
  • 14
  • 17

10 Answers10

134

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

<div style="clear:both;"></div>
Shad
  • 15,134
  • 2
  • 22
  • 34
74

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

Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
DanKodi
  • 3,550
  • 27
  • 26
33

You could modify .adm and add

.adm{
 clear:both;
}

That should make it move to a new line

Brett
  • 4,051
  • 2
  • 26
  • 39
11

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

tjm
  • 7,500
  • 2
  • 32
  • 53
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,645
  • 2
  • 14
  • 17
3

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

Trey
  • 5,480
  • 4
  • 23
  • 30
3

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

Chris Kent
  • 862
  • 11
  • 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,331
  • 2
  • 18
  • 32
sunny
  • 1
0

There's a class in bootstrap for it

class="clearfix";

TS71M
  • 33
  • 1
  • 6