简体   繁体   English

CSS 选择器,用于在具有阴影主机的 flextable 中使用字体颜色

[英]CSS selector for font color in flextable with shadow host on

I'm unsuccessfully trying to set the font color for flextable generated in r markdown using a css stylesheet.我没有成功尝试使用 css 样式表为flextable中生成的r markdown设置字体颜色。

I can accomplish this when I turn off shadow host, but not with it on.当我关闭影子主机时,我可以做到这一点,但不能打开它。 (Just turning it off removes other desirable features.) Here's a short r markdown file demonstrating the difference. (只需将其关闭即可删除其他所需功能。)这里有一个简短的 r markdown 文件展示了差异。


---
title: "Untitled"
output: html_document
---

<style>
div.flextable-shadow-host * {
  color: pink;
}

div.tabwid * {
  color: pink;
}

</style>

# ignores CSS above

```{r, echo=FALSE}
library(flextable)
flextable(head(mtcars))
```

# accepts CSS above

```{r, echo=FALSE}
ft <- flextable(head(mtcars))
htmltools_value(ft, ft.shadow = FALSE)
```


I want the css external to the r code because I have a button selector on the website the user can change the overall style (eg, dark mode or not).我想要 r 代码外部的 css 代码,因为我在网站上有一个按钮选择器,用户可以更改整体样式(例如,暗模式与否)。

When using shadow , the table is assembled outside of HTML.使用shadow时,表在 HTML 之外组装。 Only the id connects the table to HTML.只有id将表连接到 HTML。 However, flextable has functions for setting the color.但是, flextable具有设置颜色的功能。 Why not just use one of the many built-in methods to change the color?为什么不使用众多内置方法中的一种来更改颜色?

For example:例如:

# ignores CSS above

```{r liberator,include=F}
library(flextable)
library(tidyverse)

```

```{r tbler, echo=FALSE}

flextable(head(mtcars)) %>% 
  color(color = "pink", part = "all")

```

# accepts CSS above

```{r, echo=FALSE}
ft <- flextable(head(mtcars))
htmltools_value(ft, ft.shadow = FALSE)
```

在此处输入图像描述

There are many things you can do with flextable styling.使用flextable样式可以做很多事情。 You can see more customization options here .您可以在此处查看更多自定义选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM