如何减小R Shiny dashboardHeader中HTML主标题的行间距并垂直居中
你可以直接修改现有tags$style里的规则,新增针对标题的样式控制即可实现需求,调整后的完整代码如下:
dashboardPage( dashboardHeader( title = HTML("Consulta de esquemas de vacunacion"), titleWidth = 320, tags$li(a(href = '.', img(src = 'logo-s.png', title = "Reiniciar app", height = "80px"), style = "padding-top:10px; padding-bottom:10px;"), class = "dropdown"), tags$li(class = "dropdown", tags$style(".main-header {max-height: 80px; }"), # 调整logo高度和头部匹配,新增样式控制标题 tags$style(".main-header .logo { height: 80px; line-height: 1.2 !important; /* 减小行间距让内容更紧凑,可按需调整为1进一步压缩 */ display: flex; align-items: center; /* 实现垂直居中 */ padding: 0 15px; /* 左右内边距可按需修改 */ }"), # 清除标题文字默认边距,进一步压缩多余空隙 tags$style(".main-header .logo span { margin: 0 !important; }"), tags$style(".sidebar-toggle {height: 80px; padding-top: 40px !important;}"), tags$style(".navbar {min-height:80px !important}") ) ) .... )
调整逻辑说明:
- 修正了原代码中
.main-header .logo高度设为100px、和头部最大高度80px不匹配的问题,二者统一为80px - 通过
line-height参数控制文字行高,实现紧凑显示效果,数值越小行间距越窄 - 用flex布局的
align-items:center实现标题内容垂直居中,不需要手动计算上下内边距 - 新增针对logo内文字的margin清除规则,避免默认边距导致的多余空隙
内容的提问来源于stack exchange,提问作者Andres Mora
相关产品推荐
相关产品推荐

