Implement different custom CSS (font color) for kable headers in continuous tables
P粉563831052
2023-09-01 19:53:36
<p>I want a blue title and then a red title. I<code>cat</code> two HTML <code><style>...</style></code> sections, first blue and second red, according to this answer, But I get red on both. </p>
<p>How to get blue title and red title? </p>
<pre class="brush:php;toolbar:false;">---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE)
```
```{r results="asis"}
cat("
<style>
caption {
color: blue;
}
</style>
")
knitr::kable(head(iris),
format="html",
digits=4,
row.names=FALSE,
caption='Caption blue',
escape=TRUE)|>
kableExtra::kable_styling(font_size=14) |>
kableExtra::kable_paper(c('hover', 'condensed', 'responsive'), full_width=T) |>
kableExtra::scroll_box(width="100%", height="200px")
```
```{r results="asis"}
cat("
<style>
caption {
color: red;
}
</style>
")
knitr::kable(head(iris),
format="html",
digits=4,
row.names=FALSE,
caption='Caption red',
escape=TRUE) |>
kableExtra::kable_styling(font_size=14) |>
kableExtra::kable_paper(c('hover', 'condensed', 'responsive'), full_width=T) |>
kableExtra::scroll_box(width="100%", height="200px")
```</pre>
You can also provide a special HTML class for each table and collect all styles in a
css
block instead of specifying CSS in each block:Alternatively, we can insert inline CSS outside the block.
Because the second CSS overwrites the first CSS.
Better to do this:
Then use like this:
Is it valid?
greeting, Noel