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

如何在Shiny的popover中同时实现标题与列表文本两端对齐?

解决方法

要同时实现popover标题两端对齐并保留列表的原有格式,只需在CSS样式里分别指定标题和列表的规则即可:

  1. 针对popover标题对应的CSS类popover-title添加text-align: justify属性
  2. 保留原有针对popover ul的样式设置

修改后的完整代码如下:

library(shiny)
library(shinyBS)

ui <- fluidPage(
  tags$style('
    .popover-title {text-align: justify;}
    .popover ul {padding: 15px; text-align: justify;}
  '),
  br(),
  uiOutput("uiExample")
    
)
    
server <- function(input, output, session) {
  output$uiExample <- renderUI({
    tagList(
      tags$span("Little circle >>"),
      tags$span(
        popify(
          icon("info-circle", verify_fa = FALSE),
          "Placeholder",
          paste(
           "Here is an excerpt from a famous poem Still I Rise:",
           "<ul>",
             "<li>You may write me down in history With your bitter, twisted lies,</li>",
             "<li>You may tread me in the very dirt. But still, like dust, I will rise.",
             "Does my sassiness upset you...</li>",
           "</ul>"
           )
        )
      )  
    )
  })
}

shinyApp(ui, server)

说明

  • .popover-title是shinyBS中popover标题的专属容器类,单独设置它的文本对齐不会干扰其他元素
  • 原有的ul样式规则完全保留,列表的内边距和两端对齐格式都能维持不变

内容的提问来源于stack exchange,提问作者Village.Idyot

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 18:20:35