如何解决在 bookdown gitbook 中更改 R 块背景颜色
我想在 bookdown gitbook 中更改 R 块和 R 块输出的背景颜色。尝试遵循 https://bookdown.org/yihui/rmarkdown-cookbook/chunk-styling.html 第 7.3 节、Changing chunk background color in RMarkdown 或 https://github.com/yihui/knitr-examples/blob/master/116-html-class.Rmd
但没有成功。
我从这里编辑了最小的例子:https://github.com/rstudio/bookdown-demo
在style.css
.Rchunk {
background-color: #f2dede;
font-weight: bolder;
color: red;
}
.Rout {
background-color: #d9edf7;
font-weight: bolder;
color: blue;
}
这在 index.Rmd
周围 # Prerequisite
```{r,echo=FALSE}
knitr::opts_chunk$set(fig.align='center',out.width='60%',class.source="Rchunk",class.output="Rout",comment="",prompt=TRUE)
```
# Prerequisites
```{r}
summary(iris$Sepal.Length)
```
如第一张图片所示,类在 html 文件中传递,显示了 font-weight: bolder;
但不显示字体和背景颜色。它实际上就在那里,但被屏蔽了,只是另一种 css 样式
.book .book-body .page-wrapper .page-inner section.normal pre {
overflow: auto;
word-wrap: normal;
margin: 0 0 1.275em;
padding: .85em 1em;
background: #f7f7f7;
}
有没有办法去除灰色背景调用,以便可以显示彩色类?
解决方法
感谢@cderv 为我指明了正确的方向。只需要将 !important
添加到我想要优先考虑的 css 样式中:
.Rchunk {
background-color: #f2dede !important;
font-weight: bolder;
color: red !important;
}
.Rout {
background-color: #d9edf7 !important;
font-weight: bolder;
color: blue !important;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。