0
<div className="content">
 <div style={{ float: "left" }}> {pedido.nombre}</div> //name
 <div style={{ float: "right" }}> ${pedido.precio}</div> //price
</div>

it should be name at left side and price on the right side, but it stays one side of the other enter image description here

right there enter image description here

Michael Nelles
  • 5,426
  • 8
  • 41
  • 57
Drokoz
  • 11
  • 2
  • 1
    https://flexbox.io/ – azium Mar 19 '20 at 22:57
  • https://stackblitz.com/edit/typescript-apbokz?file=index.html if it really needs to be 'float'. Otherwise use flex like Robert and azium suggest - also see this guide: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ – David Renner Mar 19 '20 at 23:05
  • [So none of these worked for you?](https://stackoverflow.com/search?q=two+divs+in+a+row) – Rob Mar 19 '20 at 23:27
  • Does this answer your question? [how to place two divs besides each other](https://stackoverflow.com/questions/5792367/how-to-place-two-divs-besides-each-other) – Rob Mar 20 '20 at 01:09

3 Answers3

5

The key is to justify-content: space-between:

.content {
  display: flex;
  justify-content: space-between;
}
<div class="content">
  <div style="background: yellow">Product name</div>
  <div style="background: orange">Price</div>
</div>

The two divs will have space in between.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Robert Feduș
  • 311
  • 2
  • 16
1

While a flexbox approach works perfectly fine, I'd like to show how to achieve the described behaviour using float.

Here's the CSS

.float--left {
  float: left
}

.float--right {
  float: right
}

.clear {
  clear: both;
}

And some HTML

<div class="float--left">name</div>
<div class="float--right">price</div>

<div class="clear">other content</div>

*Note: Added a example how to reset the float behaviour back to normal using clear *

Phy
  • 248
  • 1
  • 8
0

Flexbox will help you:

Here's the HTML:

<div class="content">
    <div class="left">
        Left Side
    </div>
    <div class="right">
        Right Side
    </div>
</div>

Here's the CSS:

.content{
    display: flex;
}

.right{
    margin-left: auto;
}