如何在一行中有两个div。右边和左边

<div className="content">

 <div style={{ float: "left" }}> {pedido.nombre}</div> //name

 <div style={{ float: "right" }}> ${pedido.precio}</div> //price

</div>

它应该在左侧显示名称,在右侧显示价格,但它保留在另一侧

https://img3.mukewang.com/651138de0001633306270311.jpg

在那里

https://img1.mukewang.com/651138e8000126a206180298.jpg

HUWWW
浏览 114回答 3
3回答

幕布斯6054654

关键是justify-content: space-between:.content {&nbsp; display: flex;&nbsp; justify-content: space-between;}<div class="content">&nbsp; <div style="background: yellow">Product name</div>&nbsp; <div style="background: orange">Price</div></div>两个 div 之间会有空间。

一只名叫tom的猫

虽然 Flexbox 方法工作得非常好,但我想展示如何使用float.这是CSS.float--left {&nbsp; float: left}.float--right {&nbsp; float: right}.clear {&nbsp; clear: both;}和一些 HTML<div class="float--left">name</div><div class="float--right">price</div><div class="clear">other content</div>*注意:添加了如何使用清除将浮动行为重置回正常状态的示例*

米脂

Flexbox 将帮助您:这是 HTML:<div class="content">&nbsp; &nbsp; <div class="left">&nbsp; &nbsp; &nbsp; &nbsp; Left Side&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="right">&nbsp; &nbsp; &nbsp; &nbsp; Right Side&nbsp; &nbsp; </div></div>这是 CSS:.content{&nbsp; &nbsp; display: flex;}.right{&nbsp; &nbsp; margin-left: auto;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5