在rmd/rmarkdown中格式化h1、h2标题

4

使用外部CSS文件,我可以更改Rmd / html文档中的许多项目,但某些基本项目被Markdown插入的内联CSS覆盖(?)。

.main-container {
....
h1 {
  font-size: 34px;
}
h2 {
  font-size: 30px;
}

所以改变h2字体大小的唯一方法是直接将代码插入文档中,这很丑陋:

---
output: 
  html_document:
    theme: cosmo
   # css: whatever.css # adding h2 here does not work
---

<style type = "text/css">
h2 {color: red;}
</style>

## R Markdown

有更好的解决方案吗?是否可能抑制上述内联块?

2
你可以在自定义CSS中使用!important来覆盖默认样式。 - Iłya Bursov
1
不建议使用!important,但是在CSS中你无法比内联样式具有更高的特异性,据我所知...你必须剥离内联样式或以这种方式使用!important(https://css-tricks.com/override-inline-styles-with-css/):`element[style] { property: value !important; }` - Aziz
我尝试使用h2[style] { color: blue !important; }但没有效果,我语法有问题吗? - Dieter Menne
@DieterMenne 我们可能应该聊一下。 - Aziz
1个回答

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接