You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用PrimeFlex将Angular中的<span>test</span>置于右侧?

你只需要给<span>test</span>添加PrimeFlex的p-ml-auto类就行,这个类会设置margin-left: auto,在父容器的flex布局(p-d-flex)下,能直接把元素推到容器右侧。

如果想让test和旁边的搜索框保持点间距,可以额外加个p-mr-2类(数字2代表间距大小,你也可以换成3、4这类调整间距)。

修改后的代码如下:

<ng-template pTemplate="caption">
    <div class="p-d-flex">
        <a>
            <button>
            </button>
        </a>
        <a>
            <button></button>
        </a>
        <span class="p-ml-auto p-mr-2">test</span>
        <span class="p-input-icon-left">
            <i class="pi pi-search"></i>
            <input/>
        </span>
    </div>
</ng-template>

注意要把原来搜索框上的p-ml-auto去掉,不然搜索框会被单独推到最右侧,和test分开。

内容的提问来源于stack exchange,提问作者JBC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 22:01:18