在Quarto中,我如何编写内联CSS?

7

我想在渲染为HTML的句子中给一个单词上色。在R Markdown中,只需添加CSS标签即可完成此操作,但我不知道如何在quarto中实现这一点。 quarto文档 指出可以编写内联CSS,但没有示例。有一个超链接显示了一个R Markdown示例:

```{css, echo=FALSE}
body {
  color: red;
}
```

当我这样做时,quarto将代码显示为代码块,并且不使用CSS。

如何在quarto文档中添加CSS代码块?

1个回答

16

只需用[]将您想要样式化的单词括起来,并在{}中编写样式,就像这样。

the color is [red]{style="color: red;"}

所以单词red将会以红色显示。

为了增加更多细节,

---
title: "inline style"
format: html
---

## inline style in Quarto

We can apply styles to a sentence or a word 
by creating spans using `[]` to surround the
sentence or word that we want to style and 
use `{}` to define the style that we want to 
apply. For example,

The color of this word is [red]{style="color: red;"}. 
And [this line has a yellow background]{style="background-color: yellow"}.

渲染后,我们得到了这个:

quarto-doc-with-inline-css


1
非常感谢@shafee。这太完美了。你应该在GitHub上fork quarto文档并添加这个例子。 - itsMeInMiami
1
@itsMeInMiami,它已经在那里了,我认为这就是它 - shafee
@shafee 我们如何添加元标签,以便在聊天中分享HTML文件(WhatsApp或其他应用程序)时显示像这样的内容SO example。我特别想将自包含的HTML报告作为文本进行共享,但希望在图像和文本中显示一些信息,而不仅仅是文件名。 - user5249203
@user5249203,你能否发一个独立的问题,这样其他人和我也能够适当地回答它呢:)? - shafee
这里是带有新问题的SO文章链接:https://stackoverflow.com/questions/73925668/sharing-self-contained-html-file-as-text。 - user5249203

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