Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS: How to make <div/> float not affect the next <div/>?

I currently have:

<div style={{float:'left'}}>Left</div>
<div style={{float:'right'}}>Right</div>
<div>Below</div>

I was able to get Left and Right to be on the opposite ends like intended on the same line, but the Below is also affected, and floats to the left, right next to Left, even though float has not been defined for it.

So I was wondering how to keep Below on the next line, without being affected by the previous floats?

like image 715
Jo Ko Avatar asked Aug 17 '16 20:08

Jo Ko


People also ask

Does float work on div?

Its most common use is to wrap text around images. However, you can use the float property to wrap any inline elements around a defined HTML element, including lists, paragraphs, divs, spans, tables, iframes, and blockquotes.

How do I put div next to div?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.

How do I put two divs side by side in React?

The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.


1 Answers

You should clear the last div. Try this:

<div style={{clear:'both'}}>Below</div>
like image 166
0xRm Avatar answered Nov 15 '22 03:11

0xRm