html - React - 如何将字形图标对齐到最右边?
问题描述
我的 React 应用程序具有自动完成功能,在自动完成中我提供了列表和 glyphicon,然后如果我单击 glyphicon,内容将被插入到 MongoDB。
无论如何,我尝试将字形图标对齐到最右边,但我不能这样做。如果我将它移到 li 之外,则语法错误。
字形图标对文本是封闭的,但它应该在最右边。
我的代码如下:
<li key={_id}>{itemname}
<i className="glyphicon glyphicon-edit" onClick={() =>
this.addToReceiving(
itemid,
barcode,
itemname,
category,
stocktype,
itemtype,
wholesaleprice,
retailprice,
quantitystock,
receivingquantity,
description,
comment)}>
</i>
</li>
解决方案
您可以使用 flexbox 对齐项目。
向文本添加跨度
<li key={_id}>
<span>{itemname}</span>
<i className="glyphicon glyphicon-edit" onClick={() =>
this.addToReceiving(
itemid,
barcode,
itemname,
category,
stocktype,
itemtype,
wholesaleprice,
retailprice,
quantitystock,
receivingquantity,
description,
comment)}>
</i>
</li>
试试这个 : -
li {
display: flex;
//This will push both child elements to far corner
//You can also try justify-content: space-around; if you want some space in the corner
justify-content: space-between;
}
推荐阅读
- opengl - 是否可以将实例化渲染(例如“glDrawElementsInstanced”)与来自先前渲染过程的非实例化反馈生成数据混合在一起?
- nestjs - 当我尝试使用函数 applyDecorators 时,Nestjs 装饰器出现问题
- hyperledger-fabric - 运行 ./network.sh 时出错。超级账本
- dataframe - 在 2D 奇偶校验中可以检测到多少个最大位错误?
- c# - 更新大量数据时重复键值错误
- javascript - VScode,调试配置,launch.json,“stonOnEntry”:true 不工作
- docker - 在 ecs-cli compose docker 容器中获取 AWS 参数存储秘密
- android - 在 PreferenceFragmentCompat 中获取自定义布局的视图
- real-time-updates - jFugue可以同时使用两个播放器
- javascript - 如何在Javascript中将路径数组转换为对象?