如何在R Markdown生成的Reveal.js中对齐li::marker与嵌套dt元素
解决Reveal.js中有序列表标记与嵌套描述列表顶部对齐问题
要让有序列表的li::marker和嵌套的描述列表内容顶部对齐,只需在自定义CSS中添加针对有序列表项的对齐规则即可——Reveal.js默认的列表项布局会让内容和标记底部对齐,调整flex布局的对齐方式就能修复该问题。
修改后的最小工作示例(MWE)
--- author: CLRR date: | | Last Update: `r format(Sys.time(), '%Y/%m/%d')` output: revealjs::revealjs_presentation: self_contained: false reveal_plugins: ["notes", "search"] transition: slide pandoc_args: - --wrap=preserve --- 1. Item A ~ This is A! ~ It's good! 1. Item B ~ This is B! ~ It's new! ```{css, echo=FALSE} .reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6 { font-family: 'Roboto', 'Noto Sans JP', sans-serif; } .reveal h1, .reveal h2 { font-family: 'Roboto', 'Noto Sans JP', sans-serif; font-weight: bold; } .reveal code{ font-family: 'Roboto Mono', monospace; } .reveal pre { font-family: 'Roboto Mono', monospace; } .reveal pre code { font-family: 'Roboto Mono', monospace; } .reveal .slide { font-family: 'Roboto', 'Noto Sans JP', sans-serif; } .reveal .footer { font-size: 83%; } .columns { display: flex !important; justify-content: center; align-items: center; } .column { display: inline-block; } .uri { word-break: break-all; } .reveal .speaker-controls { font-family: 'Roboto', 'Noto Sans JP', sans-serif; } /* 新增:让有序列表标记与嵌套内容顶部对齐 */ .reveal ol li { display: flex; align-items: flex-start; }
## 关键说明 - 新增的`.reveal ol li`规则强制将有序列表项设为flex布局,并将垂直对齐方式改为`flex-start`,让列表标记(`li::marker`)与嵌套的描述列表内容顶部对齐,替代默认的底部对齐行为。 - 若只想针对嵌套了描述列表的有序列表项生效,可使用更精准的选择器:`.reveal ol li:has(dl)`,该选择器需现代浏览器支持。 内容的提问来源于stack exchange,提问作者Carlos Luis Rivera
相关产品推荐
相关产品推荐

