Implementieren Sie verschiedene benutzerdefinierte CSS (Schriftfarben) für Kable-Header in fortlaufenden Tabellen
P粉563831052
P粉563831052 2023-09-01 19:53:36
0
2
499
<p>Ich möchte einen blauen Titel und dann einen roten Titel. Ich<code>cat</code> zwei HTML-Abschnitte <code><style>...</style></code>, laut dieser Antwort, aber ich werde rot beide. </p> <p>Wie bekomme ich einen blauen und einen roten Titel? </p> <pre class="brush:php;toolbar:false;">--- Ausgabe: html_document --- „{r setup, include=FALSE} knitr::opts_chunk$set(echo=FALSE) „ „{r results="asis"} Katze(" <Stil> Untertitel { Farbe blau; } </style> ") knitr::kable(head(iris), format="html", Ziffern=4, row.names=FALSE, caption='Beschriftung blau', escape=TRUE)|> kableExtra::kable_styling(font_size=14) |> kableExtra::kable_paper(c('hover', 'pressed', 'responsive'), full_width=T) |> kableExtra::scroll_box(width="100%", height="200px") „ „{r results="asis"} Katze(" <Stil> Untertitel { Farbe Rot; } </style> ") knitr::kable(head(iris), format="html", Ziffern=4, row.names=FALSE, caption='Beschriftung rot', escape=TRUE) |> kableExtra::kable_styling(font_size=14) |> kableExtra::kable_paper(c('hover', 'pressed', 'responsive'), full_width=T) |> kableExtra::scroll_box(width="100%", height="200px") ```</pre>
P粉563831052
P粉563831052

Antworte allen(2)
P粉865900994

您还可以为每个表提供一个特殊的 HTML 类,然后将所有样式收集在 css 块中,而不是在每个块中指定 CSS:

---
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE)
```

```{css}
.mytable1 > caption {
    color: blue;
}
.mytable2 > caption {
    color: red;
}
```

```{r results="asis"}
knitr::kable(head(iris), 
             format="html",
             digits=4,
             row.names=FALSE,
             caption='Caption blue',
             escape=TRUE)|>
  kableExtra::kable_styling(font_size=14, htmltable_class = "mytable1") |>
  kableExtra::kable_paper(c('hover', 'condensed', 'responsive'), full_width=T) |>
  kableExtra::scroll_box(width="100%", height="200px") 
```


```{r results="asis"}
knitr::kable(head(iris), 
             format="html",
             digits=4,
             row.names=FALSE,
             caption='Caption red',
             escape=TRUE) |>
  kableExtra::kable_styling(font_size=14, htmltable_class = "mytable2") |>
  kableExtra::kable_paper(c('hover', 'condensed', 'responsive'), full_width=T) |>
  kableExtra::scroll_box(width="100%", height="200px")
```

或者,我们可以在块之外插入内联 CSS。

<style>
.mytable1 > caption {
  color: blue;
}
.mytable2 > caption {
  color: red;
}
</style>
P粉156983446

因为第二个CSS覆盖了第一个CSS。

最好这样做:

cat("
<style>
.blue-caption {
      color: blue;
    }

.red-caption {
      color: red;
    }
</style>
")

然后像这样使用:

caption='<span class=\"blue-caption\">Caption blue</span>',
caption='<span class=\"red-caption\">Caption red</span>',

有效吗?

问候, 诺埃尔

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!