R Markdown:如何使用内部CSS更改样式? [英] R markdown: how to change style with internal css?
问题描述
我知道如何使用自定义css文件更改R降价样式.但是,当更改很小时,我更喜欢使用内部CSS或内联CSS,以免管理两个文件带来麻烦.我用谷歌搜索,还没有找到解决方案.以下是使用外部CSS文件更改样式的简单示例.有没有办法使用内部或内联CSS?
I know how to change R markdown style with a custom css file. However, when the changes are minor, I prefer internal or even inline css, to save trouble from managing two files. I googled and haven't find a solution for this. Below is a simple example of changing style with an external css file. Is there a way to do it with internal or inline css?
R markdown文件:
The R markdown file:
---
title: "test"
output:
html_document:
css: test.css
---
## Header 1 {#header1}
But how to change style with internal css?
test.css文件:
The test.css file:
#header1 {
color: red;
}
推荐答案
Markdown接受原始HTML并将其通过原样传递,因此将样式"元素定义为HTML:
Markdown accepts raw HTML and passes it through unaltered, so define your "styled" elements as HTML:
<h2 style="color: red;">Header 1</h2>
当然,某些工具实际上不允许原始HTML通过(出于安全原因或因为最终输出不是HTML),因此您的工作量可能会有所不同.
Of course, some tools don't actually allow the raw HTML to be passed through (for security reasons or because the final output is not HTML), so your mileage may vary.
根据您使用的Markdown实现,您可以在属性列表中定义样式(如果它支持任意键):
Depending on the Markdown implementation you are using, you may be able to define styles in the attribute list (if it supports arbitrary keys):
## Header 1 {style="color: red;"}
但是,这种方法最不可能起作用.
However, that is the least likely to work.
请记住,HTML <style>
标记不需要在文档<head>
中即可工作.如果可以使用原始HTML,则可以在文档正文中包含<style>
元素(如@ user5219763在评论中指出的那样):
And remember, HTML <style>
tags do not need to be in the document <head>
to work. If you can use raw HTML, you can include a <style>
element in the body of your document (as pointed out by @user5219763 in a comment):
---
title: "test"
output:
html_document
---
<style>
#header1 {
color: red;
}
</style>
## Header 1 {#header1}
But how to change style with internal css?
这篇关于R Markdown:如何使用内部CSS更改样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!