如何在Quarto的reveal.js演示中为Markdown表格添加Bootstrap类?
在Quarto Reveal.js演示中实现Bootstrap风格的条纹悬停表格
Quarto的Reveal.js模板默认不包含Bootstrap的表格样式,因此直接给表格添加.striped和.hover类不会生效。要实现和普通HTML输出一致的表格效果,你可以通过以下两种方式解决:
方法一:自定义CSS(推荐,无样式冲突)
直接在演示文稿中添加自定义CSS,模拟Bootstrap表格的条纹和悬停效果,同时兼容Reveal.js的默认样式:
--- format: revealjs --- <style> /* 基础表格样式,对齐Bootstrap风格 */ .table { width: 100%; margin: 1rem 0; color: #212529; border-collapse: collapse; } .table th, .table td { padding: 0.75rem; vertical-align: top; border-top: 1px solid #dee2e6; } .table thead th { vertical-align: bottom; border-bottom: 2px solid #dee2e6; } /* 条纹行效果 */ .table.striped tbody tr:nth-of-type(odd) { background-color: rgba(0, 0, 0, 0.05); } /* 行悬停效果 */ .table.hover tbody tr:hover { background-color: rgba(0, 0, 0, 0.075); } </style> | fruit | price | |--------|--------| | apple | 2.05 | | pear | 1.37 | | orange | 3.09 | : Fruit prices {.table .striped .hover}
注意要在表格标题的类中添加.table,确保自定义样式能正确应用到表格上。
方法二:引入Bootstrap原生样式(需注意兼容性)
如果希望直接使用Bootstrap的官方样式,可以将Bootstrap的CSS文件下载到本地,再通过include-in-header引入本地文件:
--- format: revealjs: include-in-header: - file: bootstrap.min.css --- | fruit | price | |--------|--------| | apple | 2.05 | | pear | 1.37 | | orange | 3.09 | : Fruit prices {.table .striped .hover}
注意:这种方式可能会和Reveal.js的默认样式(如字体、间距)产生冲突,需要额外调整样式来兼容,因此更推荐方法一。
内容的提问来源于stack exchange,提问作者Quinten
相关产品推荐
相关产品推荐

